Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.