簡體   English   中英

Guzzle 身份驗證返回 400 錯誤

[英]Guzzle authentication returning 400 error

我正在嘗試在 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));

與:

$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));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM