开发者

how to stop curl php from sending accept header

By default curl sends Accept: */* header for all requests. How do I stop sending of the default开发者_如何转开发 header?

 Accept: */* 


Pass in "Accept:" (ie a header with no contents to the right of the colon) with CURLOPT_HTTPHEADER. Like:

$headers  =  array( "Accept:" );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

The equivalent using the curl command line tool is:

curl -H 'Accept:' http://example.com/

This will make curl remove the header, not just send a header with a blank value. You can also send a header with a blank value if you want, but then you need to use a semicolon instead of colon!


Make sure your array item is set up with the colon immediately following the header name, like this:

array( "Accept: yourAcceptValue" )

Not with spaces, like this:

array( "Accept : yourAcceptValue" )

If there is a space between the header name and the colon, curl will add the default */* into your headers.

(Works in PHP 5.5.9-1ubuntu4.7)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜