【发布时间】:2016-06-17 08:49:57
【问题描述】:
我正在尝试使用sendgrid v3 API to purge bounces,在 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 方法时,它可以正常工作,并返回所有的反弹。
这里是guzzle代码:
$request = $this->httpClient->delete('/v3/suppression/bounces', null, '{"delete_all": true}');
$response = $request->send();
http 客户端是使用https://api.sendgrid.com 基本 URL 初始化的服务。
【问题讨论】:
标签: symfony curl sendgrid guzzle