[thelist] php and http post requests
Roger Ly
rogerly at bareviking.com
Thu Dec 26 21:13:01 CST 2002
Hey Tom, try replacing part of your code with this:
-------
...
part of your code
...
// a file contain post data
$file = "test.xml";
$remote_url = "/xte/storesense/Process.bok";
$remote_server = "www.mydomain.com";
// read post data
$data = file($file);
// Build the header
$header = "POST $remote_url HTTP/1.0\r\n";
$header .= "Host: $remote_server\r\n";
$header .= "Content-type: application/x-www-form-urlencoded\r\n";
$header .= "Content-length: " . strlen($data) . "\r\n\r\n";
// Open the connection
$fp = fsockopen(servername($remote_url), 80);
if ($fp)
{
// Send HTTP request
fputs($fp, $header . $data);
...
rest of your code
...
--------------------
Basically, we are removing the recreating of the name/value pairs in the
existing code and just posting the raw XML (without the "?" prepended at the
beginning, which you don't need or want. Also, we are using a more accurate
HTTP header for the POST request (sending the Host: parameter, etc.)
Your HTTP header will look more or less like this when sent:
POST /xte/storesense/Process.bok HTTP/1.0
Host: www.mydomain.com
Content-type: application/x-www-form-urlencoded
Content-length: 37
<?xml version="1.0">
<XTE>
...
</XTE>
I would also suggest that you output the HTTP header that you are sending,
solely for debugging purposes so we can take a look at it if this still isn't
working for you.
Good luck!
Roger
More information about the thelist
mailing list