note 83676 added to function.curl-exec
| From: | alan at forsyth dot cz | Date: | Fri, 06 Jun 2008 22:59:14 +0000 |
| Subject: | note 83676 added to function.curl-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140199@lists.php.net to get a copy of this message | ||
Great class Roman - just one fix:
Replace the following line:
<?php
if (isset($params['host']) && $params['host'])
$header[]="Host: ".$host;
?>
with this:
<?php
if (isset($params['host']) && $params['host'])
$header[]="Host: " . $params['host'];
?>
CURL automatically creates the host parameter (since it is required for HTTP/1.1 requests), so you
don't need to set it. But if you created a custom host parameter, the above bug would cause a
'400 Bad Request' response due to invalid host specified.
Also when copying and pasting the class code, make sure that no line breaks occur (for example in
the $header and $user_agent definitions etc.). It will still be valid PHP, but the HTTP request will
not be valid, and you may get a '400 Bad Request' response from the server.
It took me a little playing around with an HTTP Sniffer before I finally got an HTTP POST request
fully working!
Thanks,
Alan
----
Server IP: 147.32.160.17
Probable Submitter: 90.177.8.71
----
Manual Page -- http://www.php.net/manual/en/function.curl-exec.php
Edit -- https://master.php.net/note/edit/83676
Del: integrated -- https://master.php.net/note/delete/83676/integrated
Del: useless -- https://master.php.net/note/delete/83676/useless
Del: bad code -- https://master.php.net/note/delete/83676/bad+code
Del: spam -- https://master.php.net/note/delete/83676/spam
Del: non-english -- https://master.php.net/note/delete/83676/non-english
Del: in docs -- https://master.php.net/note/delete/83676/in+docs
Del: other reasons-- https://master.php.net/note/delete/83676
Reject -- https://master.php.net/note/reject/83676
Search -- https://master.php.net/manage/user-notes.php