Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to stop curl php from sending accept header

Tags:

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

 Accept: */*  
like image 964
user80287 Avatar asked Oct 03 '11 17:10

user80287


People also ask

Does cURL automatically add headers?

Curl by default adds headers such as Content-type and User-agent .

How does PHP handle cURL request?

php file with the following contents. $url = 'https://www.example.com' ; $curl = curl_init(); curl_setopt( $curl , CURLOPT_URL, $url );

Why does PHP cURL?

PHP cURL is a library that is the most powerful extension of PHP. It allows the user to create the HTTP requests in PHP. cURL library is used to communicate with other servers with the help of a wide range of protocols. cURL allows the user to send and receive the data through the URL syntax.

Does PHP have cURL?

cURL is a PHP extension that allows you to use the URL syntax to receive and submit data. cURL makes it simple to connect between various websites and domains.


1 Answers

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!

like image 172
Daniel Stenberg Avatar answered Oct 05 '22 01:10

Daniel Stenberg