Api Laravel 5.1 Guzzle-未定义的偏移量:0

Api Laravel 5.1 Guzzle-未定义的偏移量:0,api,laravel-5.1,guzzle,guzzlehttp,Api,Laravel 5.1,Guzzle,Guzzlehttp,我需要访问API,所以我使用guzzle6并编写一个函数: public function test() { $client = new GuzzleHttp\Client(['defaults' => ['verify' => false]]); try { $res = $client->post('https://example.com/api/v2/oauth/token?grant_type=client_credentials', [ 'head

我需要访问API,所以我使用guzzle6并编写一个函数:

public function test()
    {

$client = new GuzzleHttp\Client(['defaults' => ['verify' => false]]);

try {
$res = $client->post('https://example.com/api/v2/oauth/token?grant_type=client_credentials', [
    'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
    ],

    'auth' => [
        'Username' => 'user_5639',
        'Password' => 'pass_asdhbas67yausihd7qaw8'
]
            ]);

$res = json_decode($res->getBody()->getContents(), true);
}

catch (GuzzleHttp\Exception\ClientException $e) {
        $response = $e->getResponse();
        $result =  json_decode($response->getBody()->getContents());

    return response()->json(['data' => $result]);
}

    }
但我有一个错误:

Client.php第346行中的ErrorException:未定义的偏移量:0

当我试着向邮递员提出同样的要求时,一切都很好:

如何解决我的问题?

如果你看一下,你会发现它需要一个数字索引数组,用户名在索引0上,密码在索引1上

因此,这应该是可行的:

$res = $client->post('https://example.com/api/v2/oauth/token?grant_type=client_credentials', [
    'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
    ],
    'auth' => [
        'user_xxxx', 'pass_xxxxx'
    ]
]);