I’m using Guzzle within my app to make a request to /connect/token/ to get a token but I got this error :
cURL error 7: Failed to connect to <url> : Connection refused
there is my code :
$this->client = new Client([
'base_uri' => $this->settings['apiUrl']
]);
$headers = [
'Content-Type' => 'application/x-www-form-urlencoded'
];
$options = [
'form_params' => [
'grant_type' => 'client_credentials',
'client_id' => 'myclientId',
'client_secret' => 'myclientsecret',
'scope' => 'my.api.website'
]];
try {
$response = $this->client->request('POST', 'connect/token', $options);
var_dump($response->getStatusCode());
var_dump($response->getBody());
} catch (RequestException $e) {
var_dump(Message::toString($e->getRequest()));
if ($e->hasResponse()) {
var_dump(Message::toString($e->getResponse()));
}
}
There is the response of the catch :
"POST /connect/token HTTP/1.1
Content-Length: 166
User-Agent: GuzzleHttp/6.5.5 curl/7.74.0 PHP/7.4.32
Content-Type: application/x-www-form-urlencoded
Host: MyBaseUrl
grant_type=client_credentials&client_id=rMyClientId&client_secret=MyClientSecret&scope=my.api.website"
I got this from my working postman request, I get the code with the “code” tab on postman
Someone have an idea about this error ? thanks