note 38281 modified in ref.curl by didou
| From: | didou@php.net | Date: | Wed, 24 Dec 2003 12:02:44 +0000 |
| Subject: | note 38281 modified in ref.curl by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62407@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
$XPost = "<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
--was--
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
http://www.php.net/manual/en/ref.curl.php