I am trying to post XML data to a remote asp server from within a PHP application and receive XML data back.
I have tried this:
function post_xml($server, $port, $url, $xml) {
$content_length = strlen($xml);
$headers = "POST $url HTTP/1.1
Accept: text/plain, text/html, text/xml, image/gif, image/jpeg,
image/png, image/bmp
Accept-Charset: UTF-8
Accept-Language: en
Content-Length: $content_length
Cache-Control: no-cache
Content-Type: text/xml
Host: $server
User-Agent: PHP
";
$fp = fsockopen($server, $port, $errno, $errstr);
if (!$fp) {
return false;
}
fputs($fp, $headers);
fputs($fp, $xml);
$ret = "";
while (!feof($fp))
$ret.= fgets($fp, 1024);
fclose($fp);
return $ret;
}
And this is the given VB example of how the posting is supposed to be done:
Dim xmlDoc
Dim xmlHTTP_
Dim ConfirmationXML
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.Load “C:\Orders.XML”
Set xmlHTTP = CreateObject("Microsoft.XMLHttp")_
xmlHTTP.Open "POST", “http://orders.somepartner.com/Orders/SubmitOrders.asp”, False_
xmlHTTP.send xmlDoc.xml___
ConfirmationXML = xmlHTTP.responseXML.xml_
I am calling the above post_xml function with the appropriate server, path, and on port 80. But I have not found any help so far on how one is supposed to post XML to an asp server, and the above does not work - it just hangs and the server doesn't seem to be responding with anything or closing the port or something.... not really sure.
How is one ideally supposed to post an XML file to an ASP server from within PHP?
Any help would be greatly appreciated.
Thanks,
Mike