I am trying to do a POST on a provider server using PHP 5.2 with cURL. I read in an XML document to publish on my server, and then read in response:
$request = trim(file_get_contents('test.xml')); $curlHandle = curl_init($servletURL); curl_setopt($curlHandle, CURLOPT_POST, TRUE); curl_setopt($curlHandle, CURLOPT_POSTFIELDS, array('XML'=>$request)); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curlHandle, CURLOPT_HEADER, FALSE);
This code itself works fine, but another server returns an XML parser response from it, which says:
Content not allowed in prolog
I looked at this error, and it is usually caused by spaces before XML, but I made sure that the XML file itself does not have spaces, and trim () should still clear it. I did TCPDump in the connection while I was running the code, and this is what was sent:
POST {serverURL} HTTP/1.1 Host: {ip of server}:8080 Accept: */* Content-Length: 921 Expect: 100-continue Content-Type: multipart/form-data; boundry:---------------------------01e7cda3896f ---------------------------01e7cda3896f Content-Disposition: form-data; name="XML" [SNIP - the XML was displayed] ---------------------------01e7cda3896f--
There are visible spaces before and after the [SNIP] line when I play a session in Ethereal. Is this what causes the problem, and if so, how can I remove it or am I looking too far, and this may be a problem with the server to which I am sending a message?
source share