原生的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