Reputation: 3971
I am sending the absolutely same request to an endpoint with Guzzle PHP and Postman extension for Chrome.
When sending the request with Postman - I do recieve the response, but when I am sending the same request with Guzzle I get "Invalid user credentials supplied".
I have the Auth type Basic and supply the same username/password for both apps. Here is the code that I use for guzzle:
$credentials = [$client->api_username, $client->decrypted_password, 'basic'];
$result = $this->client->get($fullUrl, [
'auth' => $credentials
]);
I have dumped the credentials - it is the correct array. I have double checked the Guzzle docs. Funny thing is that when I am trying to send request for another user for the same endpoint - I do recieve the correct response, which made me think, that I might have typos in credentials - but I have rechecked - and even copy pasted from Postman - still cant recieve the response :/
Upvotes: 0
Views: 1324
Reputation: 5010
Could you compare the Authentication
header from Postman and from Guzzle? If you get an exception from Guzzle, you can get it like $exception->getRequest()->getHeader('Authentication')
.
Upvotes: 0
Reputation: 457
Would you love to share what your variable $credentials
has as data?
In case try the code below it was tested and works:
$client = new Client();
$this->results = $client->request('GET/POST', $uri, [
'debug' => true,
'query' => $arguments,
'auth' => [$username, $password],
'verify' => false
])->getBody();
And if you ask about the other arguments such as verify
, this property tells guzzle to disable certificate verification.
Read below: http://docs.guzzlephp.org/en/stable/request-options.html#verify
For more information about auth
: http://docs.guzzlephp.org/en/stable/request-options.html#auth
Upvotes: 1