相关疑难解决方法(0)

如何为Http Delete方法设置RequestBody.

我正在编写一个删除API的服务器的客户端代码.API规范要求发送数据.我正在使用HttpComponents v3.1库来编写客户端代码.使用HtpDelete类我找不到向它添加请求数据的方法.有办法吗?以下是代码段.

        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);
    }
Run Code Online (Sandbox Code Playgroud)

提前致谢.

http httpclient http-delete apache-httpcomponents

5
推荐指数
2
解决办法
4744
查看次数