I'm having problems with Guzzle access to the API.
I can access the API with Postman with no problems.
If I create a simple test program, I can access the API using Postman's suggested cURL code no problem.
The problem arises if I try to use Guzzle...
This results in a 406 'Could not match accept header' error and I can't see why.
I've tried other Guzzle approaches such as...... and even a simple GET...... but they all give the same 'Could not match accept header' error.
As I say, it all works fine in Postman or with straight cURL.
What am I missing??
I can access the API with Postman with no problems.
If I create a simple test program, I can access the API using Postman's suggested cURL code no problem.
The problem arises if I try to use Guzzle...
Code:
require_once "vendor/autoload.php";$client = new \GuzzleHttp\Client();$headers = [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer c2xxxxxxx' ];$body = [ "block"=> "0", "email"=> "dum2@dum.com", "groups"=> ["2"], "id"=> "0", "lastResetTime"=> "", "lastvisitDate"=> "", "name"=> "Alan Aardvark", "params"=> [ "admin_language"=> "", "admin_style"=> "", "editor"=> "", "helpsite"=> "", "language"=> "", "timezone"=> "" ], "password"=> "klhkjh3465$%^", "password2"=> "klhkjh3465$%^", "registerDate"=> "", "requireReset"=> "0", "resetCount"=> "0", "sendEmail"=> "0", "username"=> "dum2@dum.com"];$response = $client->post('https://xxx.uk/api/index.php/v1/users', ['headers' => $headers, 'json' => $body]);
I've tried other Guzzle approaches such as...
Code:
$request = new \GuzzleHttp\Psr7\Request('POST', 'https://xxx.uk/api/index.php/v1/users', $headers, $body);$res = $client->sendAsync($request)->wait();
Code:
$request = new \GuzzleHttp\Psr7\Request('GET', 'https://lsrpc.uk/api/index.php/v1/users', $headers);$res = $client->sendAsync($request)->wait();echo $res->getBody();
As I say, it all works fine in Postman or with straight cURL.
What am I missing??
Statistics: Posted by sclg — Thu Feb 22, 2024 11:12 am