Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-17-2010, 06:35 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________

Last edited by cbk1994; 02-17-2010 at 10:42 AM..
Reply With Quote
  #2  
Old 02-17-2010, 10:34 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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).
Reply With Quote
  #3  
Old 02-17-2010, 10:43 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Stefan View Post
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.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:22 AM.


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