0

I am uploading an xml file to a supplier url. Not the content as a post, but the file itself. Regarding the response from the server, the instructions read as follows.

"For each OrderRequest from a client, the server will reply with a single OrderRequestResponse."

And:

"Once a successful order request is received, it will be placed in the queue to be run. The client shall not wait for this report to be generated – the communication over the HTTP socket will only consist of two messages – an OrderRequest, and an OrderRequestResponse."

It then goes on to say that the response may happen anywhere between 1 and 5 minutes later.

So the question is this - I would like to see the respose and make sure that the order has been accepted correctly, but how do i code for this given that i can't leave my cURL routine open for 5 minutes waiting. Can i tell the cURL request where to send the response within the parameters and then close the curl session and have my location process the response to email me or act on the content of the response.

Here is my upload code so far:

$xml = curl_file_create($thefile);
$data = array('test_file' => $xml);
$url = "www.supplierlocation.co.uk/etc";
$curlSession = curl_init();        
curl_setopt ($curlSession, CURLOPT_URL, $url);
curl_setopt ($curlSession, CURLOPT_POST, 1);
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $data);  
$ch_result = curl_exec($curlSession);
curl_close($curlSession);

What, if anything can i add so that the respose ends up somewhere that i can deal with it even after the session is closed.

[Does anybody know where i can find example of php code to respond to the response post my side. It would be an XML file that is received.]

Thanks,

hakre
  • 193,403
  • 52
  • 435
  • 836
Donquick
  • 73
  • 9
  • The quotes you did, where is the URL of the pages you quote the text from? Who is the supplier? Where does the supplier provide information about the API you interact with? – hakre Mar 24 '15 at 22:25
  • And the answer to your question *might* be: [How to get response using cURL in PHP](http://stackoverflow.com/q/6516902/367456) – hakre Mar 24 '15 at 22:27
  • @hakre - Thanks for the answer. The source is a 25 page word document that they send me, but i think that the salient point is that the response will happen after a while and be an XML file. The information abou the API is based around the required structure of the XML i must post and the location to post to - http://www.landmarkinfo.co.uk/xmlorders3/external/XMLListenerServlet – Donquick Mar 24 '15 at 22:47
  • The response happens immediately. You should be able to parse it, most likely it's a (small) XML document. That response will tell you (I guess) where you can find the generated file (in the future). It will also will tell you if your data was successfully accepted by the remote system. – hakre Mar 24 '15 at 22:55
  • Thanks - I have turned on response which should be an XML but is only a couple of expressions. Do you know how i save or store the whole response XML. Also, do you know what this means by any chance 'FAIL uk.co.landmarkinfo.xml.XMLException: org.xml.sax.SAXParseException: Content is not allowed in prolog.' Thanks – Donquick Mar 24 '15 at 23:27
  • The SAXParseException is a strong sign that the XML send to the server (at least in the form expected to receive) is not [well formed](http://en.wikipedia.org/wiki/Well-formed_document). By validating the XML file on your system first you could verify the data is OK to send (at least). Try to fail as early as possible. – hakre Mar 25 '15 at 11:20
  • Thanks hakre - you have helped me through this. I have cracked it now. The problem was that they just wanted the content of the file not the whole file with an array wrapper so i needed to read the file content into a variable and post that: $handle = fopen($thefile, "r"); $xml = fread($handle, filesize($thefile)); fclose($handle); Thanks again. – Donquick Mar 25 '15 at 22:38
  • You'll greatly benefit from the [`file_get_contents()`](http://php.net/file_get_contents) function. – hakre Mar 26 '15 at 15:25
  • thanks - i see that makes an easier solution I will change it. Again - thank you for the assistance. – Donquick Mar 27 '15 at 15:54

0 Answers0