By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,462 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,462 IT Pros & Developers. It's quick & easy.

sending http post requests

P: n/a
i'm trying to send an http post request and see if the server got it
correctly. i'm sending the http post request with this script:

<?
$address = 'domain.tld';
$port = 80;

$proxy = fsockopen("tcp://$address", (int) $port, $errno, $errstr, 1);

$extra = "extra=blah&this=test";

fputs($proxy,"POST /test.php HTTP/1.0\r\n");
fputs($proxy,"Host: $address\r\n");
fputs($proxy,"Content-Length: ".strlen($extra)."\r\n\r\n");
fputs($proxy,"$extra\r\n");

while (!feof($proxy))
print fgets($proxy);
fclose($proxy);
?>

test.php's contents are as follows:

<?
print_r($_POST);
?>

this is what i want to see:

Array
(
[extra] => blah
[this] => test
)

this is what i am seeing:

Array
(
)

any ideas as to what i'm doing wrong and how i can fix it? thanks!

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yawnmoth wrote:
i'm trying to send an http post request and see if the server got it
correctly. i'm sending the http post request with this script:

My script looks almost exactly the same (but works ;). A couple of
suggestions:
<?
$address = 'domain.tld';
$port = 80;

$proxy = fsockopen("tcp://$address", (int) $port, $errno, $errstr, 1);

Timeout seems a bit short - but OK for testing locally. The 'tcp://' was new
to me - according to the manual it's valid. Might be worth trying without.
$extra = "extra=blah&this=test";

fputs($proxy,"POST /test.php HTTP/1.0\r\n");
fputs($proxy,"Host: $address\r\n");
** maybe add : "Content-type: application/x-www-form-urlencoded\r\n";
fputs($proxy,"Content-Length: ".strlen($extra)."\r\n\r\n");
fputs($proxy,"$extra\r\n");


literal paste from my script:
$p.="Content-length: $len\n\n";
$p.= "$str\n";
$p.= "\r\n";

It was kind of a long tiime ago I wrote it, and can't recall why the first
two lines didn't get a '\r'.

HTH

C.
Jul 17 '05 #2

P: n/a

Colin McKinnon wrote:
yawnmoth wrote:
$extra = "extra=blah&this=test";

fputs($proxy,"POST /test.php HTTP/1.0\r\n");
fputs($proxy,"Host: $address\r\n");


** maybe add : "Content-type: application/x-www-form-urlencoded\r\n";


That fixed it - thanks! :)

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.