note 38281 added to ref.curl

From: Date: Mon, 15 Dec 2003 09:49:13 +0000
Subject: note 38281 added to ref.curl
Groups: php.notes 
Request: Send a blank email to php-notes+get-61974@lists.php.net to get a copy of this message
I know that many people suffer from cURL when trying to send XML data. I solved this problem and want to share it with you: I was trying to send SMS messages with a SMS service provider. They gave me the following ASP code, where you send data as XML and receive a response in XML as well: url = "http://...someaddress/somefile.asp"; xmldata ="<XMLtag1>many other tags, data here</XMLtag1>"; Set ob = Server.CreateObject("Msxml2.XMLHTTP") ob.Open "POST",url,false ob.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" ob.Send xmldata ...then recieve code was here... This is done in PHP using cURL library in this way: <?php $turkmenweb = "<XMLcontent>sameas above</XMLcontent>" $url = "..same URL as above.."; $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL,$url); // set url to post to curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4s curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields $result = curl_exec($ch); // run the whole process echo $result; //contains response from server ?> Some say that you should use CURLOPT_CUSTOMREQUEST, CURLOPT_HTTPHEADER and etc. to perform this task , as you can see you don't need those at all. Hope it will help those who tries to simulate Msxml2.XMLHTTP or simply try sending XML data over PHP. Regards, Muhammed Mamedov ---- Manual Page -- http://www.php.net/manual/en/ref.curl.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38281 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38281&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38281&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61974) next »