我向the following resource发送POST
请求并获得400分。我理解what the error means,但仍不确定为什么我在{{1}时收到该请求请求相同的资源。
GET
以下是代码的一部分:
/lists/{list_id}/members
响应
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', // <-- Drop in a GET here and it works, other than it's not the behavior I need.
env('MAILCHIMP_API_URL') . 'lists/' . env('MAILCHIMP_LIST_KEY') . '/members',
[
'auth' => ['app', env('MAILCHIMP_API_KEY')],
'query' => [
'email_address' => 'donnie@test.com',
'email_type' => 'html',
'status' => 'subscribed',
]
]);
dd($response->getStatusCode());
答案 0 :(得分:2)
您正在发送带有POST
个参数的query
个请求。您需要发送JSON
已编码的正文!
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', // <-- Drop in a GET here and it works, other than it's not the behavior I need.
env('MAILCHIMP_API_URL') . 'lists/' . env('MAILCHIMP_LIST_KEY') . '/members',
[
'auth' => ['app', env('MAILCHIMP_API_KEY')],
'json' => [
'email_address' => 'donnie@test.com',
'email_type' => 'html',
'status' => 'subscribed',
]
]);
dd($response->getStatusCode());