用apache的http包工具进行通信.(java)--有道笔记整理
2015-11-19 17:46
585 查看
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-Type", "application/json");
StringEntity entity;
try {
entity = new StringEntity(JsonUtil.object2json(parameters), "UTF-8");
httppost.setEntity(entity);
} catch(UnsupportedEncodingException e) {
logger.error("", e);
}
try {
HttpResponse httpResponse = httpclient.execute(httppost);
HttpEntity resEntity = httpResponse.getEntity();
if(null != resEntity) {
result = IOUtils.toString(resEntity.getContent(), "utf-8");
}
} catch(ClientProtocolException e) {
logger.error(e);
} catch(IOException e) {
logger.error(e);
} finally {
httpclient.getConnectionManager().shutdown();
}
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-Type", "application/json");
StringEntity entity;
try {
entity = new StringEntity(JsonUtil.object2json(parameters), "UTF-8");
httppost.setEntity(entity);
} catch(UnsupportedEncodingException e) {
logger.error("", e);
}
try {
HttpResponse httpResponse = httpclient.execute(httppost);
HttpEntity resEntity = httpResponse.getEntity();
if(null != resEntity) {
result = IOUtils.toString(resEntity.getContent(), "utf-8");
}
} catch(ClientProtocolException e) {
logger.error(e);
} catch(IOException e) {
logger.error(e);
} finally {
httpclient.getConnectionManager().shutdown();
}
相关文章推荐
- Meta http-equiv属性详解(转)
- HTTP协议详解
- http:Status常见的状态码--有道笔记的整理
- GPRS流量计算方法(TCP/IP)
- GPRS流量计算方法(TCP/IP)
- GPRS流量计算方法(TCP/IP)
- [python&php 网络编程]获取远程机器的信息
- 协议森林03 IP接力赛 (IP, ARP, RIP和BGP协议)
- [python&php 网络编程]获取服务端主机名和ip地址
- Linux CentOS 使用命令设置网络代理
- 深入理解Neutron -- OpenStack网络实现:VXLAN模式
- Mongoose6.0源码分析(2)-http数据处理
- 深入理解Neutron -- OpenStack网络实现:VLAN模式
- redhat 6.5 lighttpd web.py
- HTTP响应消息状态码说明
- nginx模块开发—HTTP初始化之listen
- 通过http获取资源
- Apache配置文件httpd.conf内容翻译
- 深入理解Neutron -- OpenStack网络实现:GRE模式
- 深入理解Neutron -- OpenStack网络实践:概述和基本概念