JAVA Http DELETE 请求 支持带报文体


     原生的JAVA API,提供HttpURLConnection请求Http。可是,当须要DELETE操做的时候,HttpURLConnection不容许Output数据。html

     于此,建议能够使用jersey + common-httpclient来解决这个问题。
java

     须要用到的依赖包:apache

     commons-codec-1.2.jarapi

     commons-httpclient-3.1.jarpost

     javax.ws.rs-api-2.0-m02.jarspa

     jersey-apache-client-1.7.jarcode

     jersey-bundle-1.5.jarhtm

    示例:blog

ApacheHttpClient client = ApacheHttpClient.create();
URI uri = new URI("http://localhost:8080/index/test");
WebResource r = client.resource(uri);
ClientResponse response = 
    r.accept(MediaType.APPLICATION_XML_TYPE,MediaType.TEXT_PLAIN_TYPE)
    .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).delete(ClientResponse.class, "m=ABC");
System.out.println(response.getEntity(String.class));
client.destroy();

 

  更多jersey-api 使用:get

   http://blog.sina.com.cn/s/blog_62e744e60100rbyf.html

   http://stackoverflow.com/questions/16284743/how-to-submit-data-with-jersey-client-post-method

   http://hugh-wangp.iteye.com/blog/1797237

相关文章
相关标签/搜索