【问题标题】:Guzzle authentication returning 400 errorGuzzle 身份验证返回 400 错误
【发布时间】:2020-10-15 11:04:16
【问题描述】:

我正在尝试在 api 沙箱中进行身份验证,但错误 400 正在返回给我,我已经通过扩展获得了它,但是在带有 guzzle 的代码中它不起作用,我需要传递带有加密授权的 Header 参数,因为它是.

 $client = new \GuzzleHttp\Client(['headers' => ['Authorization' => 'Basic $token']]);
                  $response = $client->post('', [
                        'grant_type' => 'password',
                        'scope' => 'forintegration',
                        'username' => '',
                        'password' => '',
                  ]);
                
                  $body = $response->getBody();
                  print_r(json_decode((string) $body));

【问题讨论】:

标签: laravel api guzzle


【解决方案1】:

合作:

$client = new \GuzzleHttp\Client();
              $url = "";
              $response = $client->request('POST', $url, [ 
                'headers' => [
                     'Accept' => 'application/x-www-form-urlencoded', 
                     'Authorization' => 'Basic $token'
                ],
                'form_params' => [
                     'grant_type' => 'password', 
                     'scope' => 'forintegration', 
                     'username' => '',
                     'password' => ''
                ] 
            ]);
            
              $body = $response->getBody();
              print_r(json_decode((string) $body));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-27
    • 2017-06-01
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2016-01-04
    • 2021-03-26
    相关资源
    最近更新 更多