PHP Curl Custom Headers

PHP cURL custom headers

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12'
));

http://www.php.net/manual/en/function.curl-setopt.php

PHP Setting custom header starting with ':'

:authority: looks like an HTTP/2 psuedo header, and you can't set them like this with curl. curl will however pass it on itself and it will use the same content as it would set for Host: to make it work the same way, independently of which HTTP version that is eventually used (it will also work with HTTP/3).

php curl not sending headers

Your array should be actually an array of lines! not array of different objects.

So, this should make it.

array(
'My-custom-header-name: Header-Value'
)

Like this:

curl_setopt($ch, CURLOPT_HTTPHEADER,     array(
'My-custom-header-name: Header-Value'
));

PHP, curl, Unable to set custom header

Solved. CURLOPT_FOLLOWLOCATION must be removed. For POST requests it is useless anyway.

I cannot investigate it deeply. It is not my server. As far I as know it is linked to the PHP safe mode or similar restriction. It blocks local file system requests outside the www folder and symlink usage. It affects the CURLOPT_FOLLOWLOCATION options.

PHP safe_mode problem using curl

It is an old problem. But I did not know, it removes all the headers from the request as well.



Related Topics



Leave a reply



Submit