我正在尝试使用sendgrid v3 API清除反弹,当在CLI中使用CURL时,它工作正常,这是以下命令:
curl -v -X DELETE -d '{"delete_all": true}' -H "Content-Type: application/json" -H "Authorization: Bearer SG.mykey" "https://api.sendgrid.com/v3/suppression/bounces"
但是,当尝试使用Symfony2 / Guzzle启动它时,出现了错误的请求错误,但是请求似乎还可以,这是输出(string) $request
:
"""
DELETE /v3/suppression/bounces HTTP/1.1\r\n
Host: api.sendgrid.com\r\n
Authorization: Bearer SG.mykey\r\n
User-Agent: Guzzle/3.9.3 curl/7.35.0 PHP/5.5.9-1ubuntu4.17\r\n
Accept: application/json\r\n
Content-Length: 20\r\n
\r\n
{"delete_all": true}
"""
和例外:
[Guzzle\Http\Exception\ClientErrorResponseException]
Client error response
[status code] 400
[reason phrase] BAD REQUEST
[url] https://api.sendgrid.com/v3/suppression/bounces
使用GET方法时,它可以正常工作,并且会向我返回所有弹跳。
这是the的代码:
$request = $this->httpClient->delete('/v3/suppression/bounces', null, '{"delete_all": true}');
$response = $request->send();
http客户端是使用https://api.sendgrid.com基本URL初始化的服务。
我认为您的问题是,当它只有两个时,您将发送3个要删除的参数,而您需要做的是在options数组中传递主体。
$response = $this->httpClient->delete(
'/v3/suppression/bounces',
[
'body' => json_encode(['delete_all', true]),
'Authorization' => 'Basic ' . base64_encode($username . ':' . $password),
'content-type' => 'application/json'
]
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句