I have a cUrl
request to a third party API. But it throws me an error
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
--- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
This is my code
//First fetch the GUID*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://thirdpary.asmx?op=action");
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$postarray = array(
'hashKey'=>'some-secret-key',
'username'=>'username',
'password'=>'password'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postarray));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$response3 = curl_exec($ch);
//print_r($response3 );exit;
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
$y=0;
$response3 = simplexml_load_string($response3) or die("Error: Cannot create object");
print_r($response3 );
exit;
The script is supposed to return me the guid
of the user credentials, I am sending.
I am already getting successful responses from the same API for some other requests using cUrl.
How can I fix this error?