Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Sending POST data with TSocket (https://forums.graalonline.com/forums/showthread.php?t=134258048)

cbk1994 02-17-2010 06:35 AM

Sending POST data with TSocket
 
PHP Code:

function sendPOST(hostportpathdata) {
  
// new socket
  
temp.socket = new TSocket();
  
  
// delimeter
  
temp.delim char(13) @ char(10);
  
  
// connect
  
socket.connect(hostport);
  
  
// headers
  
socket.send("POST " path " HTTP/1.0" delim);
  
socket.send("Host: " host delim);
  
socket.send("User-Agent: Mozilla/4.0 (compatible; euroCenterBot; EuroCenterGServer...lol)" delim);
  
socket.send("Content-Length: " data.length() @ delim);
  
socket.send("Content-Type: application/x-www-form-urlencoded" delim);
  
socket.send(delim);
  
  
// data
  
socket.send(data);
  
  
// wait for the socket to close
  
waitfor(socket"onClose"30);
  
  
/* for debugging
  waitfor(socket, "onReceiveData", 5);
  
  if (socket.error != null) {
    echo("Error: " @ socket.error);
  } else {
    echo("Data:");
    
    for (temp.line : socket.data.tokenize('\n')) {
      echo("  " @ line);
    }
  }*/


Example usage:

PHP Code:

temp.data urlencode("data") @ "=" urlencode("bar");
data @= "&";
data @= urlencode("data2") @ "=" urlencode("foo");

sendPOST("techxonline.net"80"/dosomething.php"data); 

Stefan has to approve each host/port for each server, so good luck with that.

Admins 02-17-2010 10:34 AM

Hmmm Normally using HTTP/1.0 and doing waitfor(socket, "onClose", 30); will be best otherwise you cannot be sure that the socket is not deleted before it has actually sent the data (since it's only stored as temp.socket).

cbk1994 02-17-2010 10:43 AM

Quote:

Originally Posted by Stefan (Post 1556713)
Hmmm Normally using HTTP/1.0 and doing waitfor(socket, "onClose", 30); will be best otherwise you cannot be sure that the socket is not deleted before it has actually sent the data (since it's only stored as temp.socket).

Ah, I didn't realize it wasn't waiting for the socket to close :) Thanks

Is there a difference in HTTP 1.0/1.1 in this case? I was having some problems with 1.0, and changing it to 1.1 fixed the problem.


All times are GMT +2. The time now is 09:16 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.