私はAPIを削除するサーバーのクライアントコードを書いています。 API仕様では、データの送信が必要です。私はクライアントコードを書くためにHttpComponents v3.1ライブラリを使用しています。 HtpDeleteクラスを使用すると、リクエストデータを追加する方法が見つかりませんでした。そうする方法はありますか?以下はコードスニペットです。Http DeleteメソッドのRequestBodyを設定する方法。
HttpDelete deleteReq = new HttpDelete(uriBuilder.toString());
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair(RestConstants.POST_DATA_PARAM_NAME,
postData.toString()));
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams);
entity.setContentEncoding(HTTP.UTF_8);
//deleteReq.setEntity(entity); // There is no method setEntity()
deleteReq.setHeader(RestConstants.CONTENT_TYPE_HEADER, RestConstants.CONTENT_TYPE_HEADER_VAL);
} catch (UnsupportedEncodingException e) {
logger.error("UnsupportedEncodingException: " + e);
}
ありがとうございます。
をしない:それはどのようなAPIのですか? (DELETE要求本体が必要です) –
そのサードパーティのカスタムREST APIです。 :) –