Curl Auth Returning Strange Carcteres

Asked

Viewed 32 times

0

Hello, I am accessing an api that when sending an auth2 with clientId and clientsecret is received the token for validation in other requests; The problem is that when receiving the token I cannot see the characters, so I cannot save and use later. Follow the code in php:

    $rota = "http://xxx.com.br/authentication/v1.0/oauth/token";

    $data = http_build_query(['grant_type' => 'client_credentials', 'clientId' => $clientId, 'clientSecret' => $clientSecret]);

    $process = curl_init($rota);
    curl_setopt($process, CURLOPT_HTTPHEADER, ["Content-Type: application/x-www-form-urlencoded"]); 
    curl_setopt($process, CURLOPT_POST, true);
    curl_setopt($process, CURLOPT_POSTFIELDS, $data);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, true); 
    $resp = curl_exec($process);
    $err = curl_error($process);

    var_dump($resp);

The exit is something:

string(91) " J /R Irrjl J-,M-. Q M-.NL { % d ( % ( T

I had already seen another question similar to mine here in the forum, I used the code but I continue with the same problem, putting echo, print_r, the output is always the strange characters; I am using the Ifood API, and in this first request is used the Curl command:

    curl -X POST "https://xxx/authentication/v1.0/oauth/token" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "grantType=client_credentials&clientId=1111&clientSecret=1111&authorizationCode=&authorizationCodeVerifier="

API documentation: https://developer.ifood.com.br/docs/references#Operations-Oauth-oauthTokenV1

1 answer

1


curl_setopt($process, CURLOPT_ENCODING, '');

Add to code;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.