Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php curl not sending headers

Tags:

php

curl

php-curl

I'm trying to send headers using php curl - which should be rather simple - but there seems to be an issue.

Running on PHP 7.2 I'm setting the headers with

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

When trying to print info before curl_exec with

curl_getinfo($ch);

I have the following result :

enter image description here

The header part remains empty, is it because it shows response headers ? If yes, how to ensure that the headers are set correctly ?

I have an access to the remote address I'm trying to reach and I can see, well, can't see, the previously set headers. I would like to make sure they are attached to the curl request before investigating somewhere else.

The same request is working fine from local to remote addr, are there changes between php 7.1 and 7.2 that I'm not aware of ?

EDIT : I added

curl_setopt($ch, CURLINFO_HEADER_OUT, true);

but now the following :

curl_getinfo($ch, CURLINFO_HEADER_OUT);

gives

POST /someurl HTTP/1.1
Host : Some host
Accept: */*
Content-Length: 153
Content-Type: application/x-www-form-urlencoded

I don't see my custom headers.

Thank you very much for your time.

like image 379
thiout_p Avatar asked Aug 29 '26 17:08

thiout_p


1 Answers

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'
        ));
like image 97
Kram Avatar answered Aug 31 '26 09:08

Kram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!