Posting XML with CURL
Posted: Fri Jul 17, 2009 9:04 am
Hi,
I'm trying to post xml data using CURL but I keep getting errors returned. Since the XML is for work I'm not allowed to post it in full, but I have been assured that it is correctly formatted.
Here is my code:
I get the following error:
If anyone has any ideas as to why this doesn't work I'd greatly appreciate your help!
Thanks,
J
I'm trying to post xml data using CURL but I keep getting errors returned. Since the XML is for work I'm not allowed to post it in full, but I have been assured that it is correctly formatted.
Here is my code:
Code: Select all
<?php
$url = "https://myurlexample.com/findproducts";
$request_xml = '<?xml version="1.0" encoding="UTF-8"?>
// Purposely truncated
</request>';
$header = "POST /findproducts HTTP/1.1 \r\n";
$header .= "Content-type: application/xml \r\n";
$header .= "Accept: application/xml \r\n";
$header .= "Cache-Control: no-cache \r\n";
$header .= "Pragma: no-cache \r\n";
$header .= "Connection: keep-alive \r\n";
$header .= "Content-length: ".strlen($request_xml)." \r\n\r\n";
$header .= $request_xml;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, 'jkwok:run467pGH3');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_xml);
$reply = curl_exec($ch);
if(curl_errno($ch))
print curl_error($ch);
else
curl_close($ch);
echo "<xmp>$reply</xmp>";
?>
Code: Select all
HTTP/1.1 100 Continue
HTTP/1.1 500 Internal Server Error
Connection: close
Server: Jetty(6.1.12.rc2)
Thanks,
J