sending HTTP requests
Posted: Tue Jan 07, 2003 11:35 pm
Ok, I've been busting my head over this for the past couple days, and was hoping someone on this forum could help me out here.
This is the first time i've attempted to code something to send and recieve an http request automatically, and was wondering if there was something in my code that is fundamentally wrong.
I am invoking a service online, sending it an xml document, and it is supposed to respond with one. The only response i get is an http response statying status 100, which means continue, so obviously something passed. Then I get another http response right after that giving me a 400 error, which means its not recognizing my request (problem in the header i'm sending.) Here is a look at my code.
so that is my code, and it puts into the text box the response. I've already explained the response i'm getting, and it has to do with something being wrong with my HTTP header i'm sending, but i'm not sure what. Maybe someone here can shed some light on what i'm doing wrong. Would be greatly appreciated.
This is the first time i've attempted to code something to send and recieve an http request automatically, and was wondering if there was something in my code that is fundamentally wrong.
I am invoking a service online, sending it an xml document, and it is supposed to respond with one. The only response i get is an http response statying status 100, which means continue, so obviously something passed. Then I get another http response right after that giving me a 400 error, which means its not recognizing my request (problem in the header i'm sending.) Here is a look at my code.
Code: Select all
<?php
$holdmessage = 'xmlrequest';
$messagesize = strlen($holdmessage);
$query = "POST /ShippingAPITest.dll HTTP/1.1\r\n".
"Host: testing.shippingapis.com:80:\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: ".$messagesize."\r\n\r\n";
$fp = fsockopen("testing.shippingapis.com",80);
if (!$fp)
echo "FAIL!";
else {
$len = strlen($query);
fputs($fp, $query, $len);
fputs($fp, $holdmessage, $messagesize)
}
echo "<html><body><form>";
echo "<textarea name='resultmessage' rows='30' nowarp cols='80'>";
echo fpassthru($fp);
echo "</textarea></form></body></html>";
?>
}