Jump to content

CURL


juggy

Recommended Posts

Hi,

I have server which is posting me these data through curl.

$strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    $strPost .= "<request>";
    $strPost .= "<type>login</type>";
    $strPost .= "<session>21</session>";
    $strPost .= "</request>";
    $url = "http://www.abc.com/xyz.php";
    
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);	
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPGET,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HEADER, FALSE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost); // add POST fields
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
    if($result == true) {
	echo $result;
}
    curl_close($ch);

 

I wanna read the above xml send i.e $strPost at http://www.abc.com/xyz.php i m trying to read it with $_POST['strPost'] but shows empty.

Can anyone help me.

Link to comment
https://forums.phpfreaks.com/topic/237990-curl/
Share on other sites

  • 5 weeks later...

I too am having similar issues.

 

All the tutorials and forum posts i read say to do as the OP suggests, however the $strPost (in the above example) simply gets posted as a string, which wouldn't be the end of the world except that the equals sign in <?xml version=\"1.0\" creates a post key and value of

$_POST['<?xml version']="\"1.0\"....etc."

 

I was under the impression that including the line

 curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); 

would either make curl convert the XML data into the appropriate POST values or at least leave the XML intact.

 

There are no errors reported and if I pass a string such as name=bob&age=50&job=caretaker it all works fine.

Link to comment
https://forums.phpfreaks.com/topic/237990-curl/#findComment-1236819
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.