2016-06-17 2 views
0

をsendgridを使用する際にCLIにCURLを使用した場合、それが正常に動作返され、ここにコマンドです:悪い要求ががつがつ食うとカール方法を削除し、私は<a href="https://sendgrid.com/docs/API_Reference/Web_API_v3/bounces.html#Delete-bounces-DELETE" rel="nofollow">sendgrid v3 API to purge bounces</a>を使用しようとしている

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の/がつがつ食うとそれを起動し、私は不正な要求エラーを取得しています、しかし要求はOKらしい、ここ(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メソッドを使用すると正しく動作し、すべてのバウンスを返します。ここで

はがつがつ食うコードです:

$request = $this->httpClient->delete('/v3/suppression/bounces', null, '{"delete_all": true}'); 
$response = $request->send(); 

HTTPクライアントはhttps://api.sendgrid.comベースURLで初期化するサービスです。

答えて

1

あなたの問題私は、2つしかないときに3つのパラメータを送信していると思っています。代わりに、あなたが行う必要があるのはオプションの配列で本体を渡すことです。自分自身に答える

$response = $this->httpClient->delete(
     '/v3/suppression/bounces', 
     [ 
      'body' => json_encode(['delete_all', true]), 
      'Authorization' => 'Basic ' . base64_encode($username . ':' . $password), 
      'content-type' => 'application/json' 
     ] 
    ); 

Guzzle options docs

+0

私はコンテンツタイプのヘッダーを指定した答えを受け入れています。しかし、これはあなたの助けを借りてGuzzle6のためにあります。 – COil

+0

私はあなたがGuzzle/3.9.3にいることに気付かなかったので、私はそれを動作させるために何をしたのか見てみました。 –

0

。問題はかなり分かりました。コンテンツタイプヘッダーが設定されておらず、 "受け入れる"ものがありました。私はこのヘッダーを気にしませんでした。なぜなら、このAPIのGETメソッドを使用するときに渡す必要がないからです。だから私の要求オブジェクトをデバッグするとき私は持っています:

""" 
DELETE /v3/suppression/bounces HTTP/1.1\r\n 
Host: api.sendgrid.com\r\n 
Authorization: Bearer SG.mykey\r\n 
Content-Type: application/json\r\n 
Content-Length: 20\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 
\r\n 
{"delete_all": true} 
""" 
関連する問題