jar archive: http://archive.apache.org/dist/httpcomponents/html
基于httpclient 2.0 final的demo(for jdk1.5/1.6): java
http://alvinalexander.com/java/jwarehouse/commons-httpclient-2.0/src/examples/PostXML.shtmlapache
基于httpclient 4.x的demopost
import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.HttpClients; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.apache.http.entity.ByteArrayEntity; public class Test{ public static void main(String[] args) throws Exception { post(); } public static void post() throws Exception{ //HttpClient client = new DefaultHttpClient(); CloseableHttpClient client = HttpClients.createDefault(); HttpPost post = new HttpPost("http://xxx.xxx.xxx/csc/maintaining_info"); String xml = "<xml>xxxx</xml>"; HttpEntity entity = new ByteArrayEntity(xml.getBytes("UTF-8")); post.setEntity(entity); HttpResponse response = client.execute(post); String result = EntityUtils.toString(response.getEntity()); System.out.println(result); } }
后记:spa
基于历史jar包来写代码时,首先忘掉需求。code
先去看对应版本的doc。 而后反过来再写!component
不然很房费时间!xml
选对版本,选对文档,java也能够简单暴力!htm
来源:http://www.cnblogs.com/Tommy-Yu/p/6402751.htmlblog