I'm trying to perform Http request in php which should open a web page so that I would look for a code that would come in the URL after authorizing the API. But when I run the page it goes blank. I tried cURL and the result really was.
<?php
$request = new HttpRequest();
$request->setUrl('https://api.contaazul.com/auth/authotize');
$request->setMethod(HTTP_METH_GET);
$request->setQueryData((
'redirect_uri' => 'http://contaazul.com',
'cliente_id' => '',
'scope' => 'sales',
'state' => 'DCEeFWf45A53sdfKef424'
));
try{
$response = $request->send();
echo $responde->getBody();
} catch (HttpException $ex) {
echo $ex;
}
?>
Could someone give me a light where I might be wrong? I did the authentication for Postman and it worked as expected, the only difference is that there was "Postman-Token" in the header. But I tested with it and still no success.
In cURL it was as follows:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.contaazul.com/auth/authorize?redirect_uri=http://contaazul.com&client_id={CLIENTE_ID}&scope=sales&state=DCEeFWf45A53sdfKef424",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
It also worked on Postman.