I have a form that sends the information to an api and gets a response in XML format. I need to know what the best way to document/parse the results (text document, or anything else). If possible i would like the responses to all save into one document and not single documents for every result.
i’m using an ajax post method and the localproxy code where the results code needs to be is below
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://integrate.com/api/test.ashx');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
file_put_contents('mydata.xml', $result, FILE_APPEND);
die('<h1>Thanks!</h1>');
?>
the xml data comes in the format below
<result>
<success>0</success>
<leadid/>
<errors>
<error>Missing Field: </error>
</errors>
</result>
The file gets created and has content in it now, this is the content, it is an error
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Content Length</h2>
<hr><p>HTTP Error 400. There is an invalid content length or chunk length in the request.</p>
</BODY></HTML>
what does this mean? the api server isn’t accepted the request?
As for parsing xml, use
XML parserTo save the result in a file, appending each result to the end of the file you could use
file_put_contents($filename, $data, FILE_APPEND)e.g.
If you need to send a post request add: