juggy Posted May 31, 2011 Share Posted May 31, 2011 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 More sharing options...
Maq Posted May 31, 2011 Share Posted May 31, 2011 In the future, please place tags around your code. Link to comment https://forums.phpfreaks.com/topic/237990-curl/#findComment-1222929 Share on other sites More sharing options...
pandyboy Posted June 30, 2011 Share Posted June 30, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.