25

By default curl sends Accept: */* header for all requests. How do I stop sending of the default header?

 Accept: */* 

2 Answers 2

35

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!

Sign up to request clarification or add additional context in comments.

1 Comment

I stumbled across a related question prior to reaching this one, and wanted to point out -H 'Accept:' does in fact prevent curl from sending the header altogether. It doesn't send the header as empty as I first thought it would.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.