0
從API文檔我有這樣的要求curl
:Laravel狂飲參數
curl https://api.example.com/api/Jwt/Token^
-d Username="asd%40gmail.com"^
-d Password="abcd1234"
現在我試圖創建一個使用狂飲庫Laravel 5.1這一要求,所以我寫道:
public function test()
{
$client = new GuzzleHttp\Client();
$res = $client->createRequest('POST','https://api.example.com/api/Jwt/Token', [
'form_params' => [
'Username' => 'asd%40gmail.com',
'Password' => 'abcd1234'
]
]);
$res = json_decode($res->getBody()->getContents(), true);
dd ($res);
}
但我得到這個錯誤:
***ErrorException in Client.php line 126:
Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given, called in /home/ibook/public_html/vendor/guzzlehttp/guzzle/src/Client.php on line 87 and defined***
問題是什麼,如何解決這個錯誤?
p.s.我也試過
$res = $client->createRequest('POST','https://api.example.com/api/Jwt/Token',
'form_params' => [
'Username' => 'asd%40gmail.com',
'Password' => 'abcd1234'
]);
但後來我得到:
syntax error, unexpected '=>' (T_DOUBLE_ARROW)