Jump to content

Recuperar cabeçalhos enviados pelo cURL no Server


Carlos Rocha

Recommended Posts

Boas,

Estou fazendo uma interação cliente servidor com PHP.

Tenho a seguinte função no cliente:

function login (string $_login, string $_senha) : string {

	$url = "https://acweb.net.br/api/orcamentos/login";  

	$fields = [
		"login" => $_login,
		"senha" => $_senha
	];

	$headers = [
		"Try           : Trying",
		'Content-Type  : application/json'
	];

	$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_HTTPHEADER, $headers);
	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);

	return curl_exec( $ch );

}

Que eu chamo dessa forma

 $retorno = login( "carcleo@gmail.com", "aaaa" );

No servidor, eu recupero as variáveis que foram enviadas pelo cURL via POST da forma abaixo 

var_dump( $_POST );

Agora, ainda no lado do servidor, desejo recuperar as variáveis que foram enviadas pela cURL mas no cabeçalho da requisição

Se eu descomentar a linha abaixo:

#curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);

e fazer da forma que tenho visto nos fóruns:

var_dump ($_SERVER [ "HTTP_TRY" ]);

Obtenho o seguinte erro da cURL :

string(432) "HTTP/1.1 400 Bad Request Date: Fri, 13 Dec 2019 17:49:23 GMT Server: Apache/2.4.41
(Win64) PHP/7.3.9 OpenSSL/1.1.1c Content-Length: 226 Connection: close Content-Type: text/html;
charset=iso-8859-1
Bad Request
Your browser sent a request that this server could not understand.

Já não sei mais o que fazer para recuperar esse cabeçalho.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.