curl-library
Re: Getting the outgoing request header
Date: Fri, 27 Jan 2006 10:12:03 +0100 (CET)
On Fri, 27 Jan 2006, Kenneth Andresen wrote:
> Using libcurl with php, and am on a particular page getting odd results when
> using the following code:
There's a separate mailing list for PHP/CURL that you might enjoy:
curl-and-php... Do pay attention that you are in fact *not* using libcurl from
PHP, you use the PHP/CURL binding which is a layer ontop of libcurl and as
such it offers a slightly different set of features and options than what pure
and plain libcurl does.
> $header[] = 'GET '.$uri.' HTTP/1.1';
This is not a header. This is the actual request/method line and this is
explained in the docs. (That is, the libcurl docs - the PHP binding is lacking
in the docs department.) You adding this will simply add an invalid header to
your outgoing request. I fully understand why servers don't like that.
> $header[] = 'Host: '.$domain;
libcurl adds Host: by itself so unless you have a compelling reason to do
this, you are better off letting libcurl add this header.
> $header[] = 'Accept-Encoding: gzip,deflate';
You are aware that by adding this header "manually" instead of using
CURLOPT_ENCODING will make the contents to get delivered in a compressed
state, where as if you'd use the option it would be uncompressed automatically
by libcurl?
> curl_setopt($ch, CURLOPT_ENCODING, ""); #"gzip,deflate,compress"
Right, but then why add the custom header above as well?
> When commenting out the CURLOPT_HTTPHEADER line the result is ok, but I am
> not getting the expected return from the script with my custom headers. In
> Firefox which I try to mimic, the result however is ok, so I assume some
> headers are not sent as expected. How can I trouble shoot what my requested
> headers really where?
You typically use CURLOPT_DEBUGFUNCTION or CURLOPT_VERBOSE to see how your
outgoing request looks like and what headers you get back and then you compare
them with that Firefox sends/receives.
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.htmlReceived on 2006-01-27