如何使用枪口发送用于基本身份验证的正确授权标头

问题描述 投票:0回答:1

如何使用枪口发送用于基本身份验证的正确授权标头

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"}}
php guzzle
1个回答
0
投票

Referring to documentation,您应该在请求方法中传递auth参数,而不是客户端的构造函数:

$client = new Client();
$res = $client->request(
    'GET',
    'past-url-here',
    ['auth' => [$username, $password]]
);
© www.soinside.com 2019 - 2024. All rights reserved.