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>";
?>
}