我想使用Guzzle Http来调用外部API。我的代码中buffer
的请求使用了错误的结构。
这是body
中的json body
,它很不错:
postman
这是我希望工作的// json body that works fine on postman.
{
"field_1": "aaa",
"field_2": "bbb",
"field_3": [
{
"field_a": "ccc",
"field_b": "ddd",
}
]
}
:
equivalent code
这会导致此错误:
use GuzzleHttp\Client;
$client = new Client;
$response = $client->request('POST',
"https://api.test.com/v1/some-endpoint",
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer some-access-token',
],
'json' => [
'field_1' => "aaa",
'field_2' => "bbb",
'field_3' => [
'field_a' => "ccc",
'field_b' => "ddd",
],
],
]
);
答案 0 :(得分:-2)
替换
$client = new Client;与
$client = new Client();