note 38281 deleted from ref.curl by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 19:43:42 +0000 |
| Subject: | note 38281 deleted from ref.curl by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155257@lists.php.net to get a copy of this message | ||
Note Submitter: mmm at turkmenweb dot com
----
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