博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java httpclient post xml demo
阅读量:4365 次
发布时间:2019-06-07

本文共 1364 字,大约阅读时间需要 4 分钟。

jar archive: http://archive.apache.org/dist/httpcomponents/

 

 

基于httpclient 2.0 final的demo(for jdk1.5/1.6): 

http://alvinalexander.com/java/jwarehouse/commons-httpclient-2.0/src/examples/PostXML.shtml

 

基于httpclient 4.x的demo

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 = "
xxxx
"; 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); }}

 

后记:

基于历史jar包来写代码时,首先忘掉需求。

先去看对应版本的doc。 然后反过来再写!

否则很房费时间!

 

选对版本,选对文档,java也可以简单暴力!

 

来源:http://www.cnblogs.com/Tommy-Yu/p/6402751.html

转载于:https://www.cnblogs.com/Tommy-Yu/p/6402751.html

你可能感兴趣的文章
asterisk拨号规则
查看>>
NSMutableDictionary中 setValue和setObject的区别
查看>>
ubunu安装软件的一个错误
查看>>
hibernate配置
查看>>
ORM框架greenDao 2 (用于了解旧版本的使用方法,目前最新版本为3.2.2,使用注释的方式来生成)...
查看>>
解决ios8下coreData没有NSPersistentContainer的问题
查看>>
玩转Android之加速度传感器的使用,模仿微信摇一摇
查看>>
Android 菜单(OptionMenu)大全 建立你自己的菜单
查看>>
Linux驱动开发常用头文件
查看>>
Linux虚机安装配置Tomcat
查看>>
[LeetCode]Find Minimum in Rotated Sorted Array
查看>>
CentOS 7安装redis及php扩展
查看>>
大龄程序员怎样渡过中年危机?(转)
查看>>
浅谈算法和数据结构: 七 二叉查找树
查看>>
Hbuilder MUI 下拉选择与时间选择器
查看>>
MyBatis 入门到精通(二) SQL语句映射XML文件
查看>>
mysql查询优化之一:mysql查询优化常用方式
查看>>
MyBatis ResultMap(2)
查看>>
JavaScript学习第一天(一)
查看>>
C语言基础小斋
查看>>