如何使用枪口发送用于基本身份验证的正确授权标头
use GuzzleHttp\Client;
$username='EFDEMO';
$password='EFDEMO';
$client = new Client(['auth' => [$username, $password]]);
$res = $client->request('GET', 'https://mb-
rewards.calusastorefront.p2motivate.com/client/json.php/
getMemberAccount');
$res->getStatusCode();
$response = $res->getBody();
echo $response;
the error I am getting
{"statusCode":"Error","error":
{"errorCode":"400","errorMessage":"Authentication Header ID field must
match Basic Authentication Username"}}
Referring to documentation,您应该在请求方法中传递auth参数,而不是客户端的构造函数:
$client = new Client();
$res = $client->request(
'GET',
'past-url-here',
['auth' => [$username, $password]]
);