1

I have the method below that is to get the response from webserver using cURL.

function login (string $_login, string $_password) : string { $url = "https://acweb.net.br/api/orcamentos/login"; $fields = [ "login" => $_login, "password" => $_password ]; $headers = [ "Try" => "Trying" ]; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url); curl_setopt( $ch, CURLOPT_POST, true); curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); return curl_exec( $ch ); } 

It works fine!

i can get the value of $_POST with

print_r ($_POST) 

But i can't get the value of CURLOPT_HTTPHEADER.

EDIT:

I did try so:

print_r ($_SERVER) 

but it wasn't there.

How can i get the value of CURLOPT_HTTPHEADER?

all HTTP_headers in $_SERVER:

[HTTP_HOST] => ctemcasb.com.br [HTTP_CONNECTION] => keep-alive [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36 [HTTP_SEC_FETCH_USER] => ?1 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 [HTTP_SEC_FETCH_SITE] => none [HTTP_SEC_FETCH_MODE] => navigate [HTTP_ACCEPT_ENCODING] => gzip, deflate, br [HTTP_ACCEPT_LANGUAGE] => pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7 [HTTP_COOKIE] => PHPSESSID=j4cqqdc83fia68nk0gsglqk1bv 

HTTP_TRY, not exists.

And now?

I did this in the server:

print_r($_SERVER) 

and

print_r ($_SERVER["HTTP_TRY]); 
0

1 Answer 1

5

The headers shouldn't be an associative array, it should be an indexed array of strings.

$headers = [ 'Try: Trying', 'Content-Type: text/html', ... ]; 

Then you should be able to access the header with: $_SERVER['HTTP_TRY'] since custom headers are prefixed with HTTP_

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

10 Comments

The, i put on the end of question explain that i dont be able to do.
@CarlosRocha - I'm sorry, but I have no idea what you mean. I tested your code, both your way of adding headers and the above way. Your way didn't work but the above did.
see in the end of the question please
Ii am doing so print_r( $_SERVER['HTTP_TRY']);, and said that not exists.
@CarlosRocha - I can't answer that, since it works when I test it. There must be something else going on somewhere else. Check that you don't have some extension installed/enabled, web server config or similar that filters custom headers.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.