note 77502 added to ref.curl
| From: | charles at tastik dot net | Date: | Sat, 01 Sep 2007 09:27:45 +0000 |
| Subject: | note 77502 added to ref.curl | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129955@lists.php.net to get a copy of this message | ||
FYI,
Anyone trying to connect to .NET with CURL to send a simple XML post, pay attention to the
following. This will save you hours! There is a previous note that I saw either on this page, or
somewhere else on this site that explains the correct way to specify the header option is to create
an array, then reference the array from the CURLOPT.
ie. Do something like this:
// Req. HTTP Header Values
$header[] = "Content-type: text/xml";
// Target URL
$sendTo = "http://www.blah.com";
// Post Data
$post = "<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<root>\n....etc, etc,";
// Create CURL Connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'XtraDoh xAgent');
curl_setopt($ch, CURLOPT_URL, $sendTo);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
Notice the HTTPHEADER, $header above. I have not been able to get .NET to properly read the HTTP
header as specified (in this case as text/xml) when using the following:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type'=>'text/xml'));
Although this may work when working with other PHP, IIS, or even PHP, Apache, it does not (at least
in my experience) work with .NET, IIS.
----
Server IP: 209.41.74.194
Probable Submitter: 72.193.117.46
----
Manual Page -- http://www.php.net/manual/en/ref.curl.php
Edit -- https://master.php.net/note/edit/77502
Del: integrated -- https://master.php.net/note/delete/77502/integrated
Del: useless -- https://master.php.net/note/delete/77502/useless
Del: bad code -- https://master.php.net/note/delete/77502/bad+code
Del: spam -- https://master.php.net/note/delete/77502/spam
Del: non-english -- https://master.php.net/note/delete/77502/non-english
Del: in docs -- https://master.php.net/note/delete/77502/in+docs
Del: other reasons-- https://master.php.net/note/delete/77502
Reject -- https://master.php.net/note/reject/77502
Search -- https://master.php.net/manage/user-notes.php