CloseableHttpClient(二)
package com.cmy.httpClient; import java.io.IOException; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test; public class HttpClientTest { @Test
public void jUnitTest(){
get();
} public void get(){
CloseableHttpClient client = HttpClients.createDefault();
try {
HttpGet httpget = new HttpGet("http://www.baidu.com/");
HttpPost httppost = new HttpPost("http://www.mi.com/en/");
System.out.println("executing resutlt url: "+httpget.getURI());
System.out.println("executing resutlt url: "+httppost.getURI());
System.out.println("executing resutlt url: "+httpget.getMethod());
System.out.println("executing resutlt url: "+httppost.getMethod()); CloseableHttpResponse response = client.execute(httppost);
try {
HttpEntity entity = response.getEntity();
System.out.println("响应状态: "+response.getStatusLine());
if(entity!=null){
System.out.println("响应长度: "+entity.getContentLength());
System.out.println("响应内容: "+EntityUtils.toString(entity));
}
} catch (Exception e) {
e.printStackTrace();
} } catch (Exception e) {
e.printStackTrace();
}finally{
try { client.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
}
CloseableHttpClient(二)的更多相关文章
- httpclient案例二(调用百度地图的接口)
一,class T package com.http.test; import org.junit.Test; import com.http.BaiduMapProxyService; import ...
- Java进阶(三十二) HttpClient使用详解
Java进阶(三十二) HttpClient使用详解 Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们 ...
- 微信二维码支付-模式一(PC端,解决中文乱码问题)
近期公司调完银联,调支付宝,调完支付宝调微信.说实话微信的帮助文档确实是烂,而且有没有技术支持,害的我头发都掉了一桌.不说废话了,看代码. 首先登陆微信的公众平台(微信的服务号不是订阅号),然后选择微 ...
- Java生成名片式的二维码源码分享
世界上25%的人都有拖延症——但我觉得这统计肯定少了,至少我就是一名拖延症患者.一直想把“Java生成名片式(带有背景图片.用户网络头像.用户昵称)的二维码”这篇博客分享出来,但一直拖啊拖,拖到现在, ...
- 开源)嗨,Java,你可以生成金山词霸的二维码分享海报吗?
As long as you can still grab a breath, you fight.只要一息尚存,就不得不战. 有那么一段时间,我特别迷恋金山词霸的每日一句分享海报.因为不仅海报上的图 ...
- httpClient4.5 closeableHttpClient用法
HttpClient一 简介1.尽管java.net包提供了基本通过HTTP访问资源的功能,但它没有提供全面的灵活性和其它很多应用程序需要的功能.HttpClient就是寻求弥补这项空白的组件,通过提 ...
- java 生成微信的二维码 工具类
package com.app.wii.util; import java.io.File;import java.io.FileInputStream;import java.io.FileOutp ...
- springboot系列十二、springboot集成RestTemplate及常见用法
一.背景介绍 在微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使用HTTP客户端.我们可以使用JDK原生的URLConnection.Apache的Http Client.N ...
- Java获取微信小程序二维码
tip:通过该接口,仅能生成已发布的小程序的二维码. tip:可以在开发者工具预览时生成开发版的带参二维码. tip:接口A加上接口C,总共生成的码数量限制为100,000,请谨慎调用. tip: P ...
随机推荐
- poj 3253 Fence Repair (贪心,优先队列)
Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...
- 【整理总结】代码沉淀 - CefSharp - 比较流行的第三方内嵌浏览器组件
.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework web: https://github.com/ce ...
- pip 安装指定版本的python包
pip install -v package_name==2.3
- 【POJ】2480 Longge's problem(欧拉函数)
题目 传送门:QWQ 分析 题意就是求∑gcd(i, N) 1<=i <=N.. 显然$ gcd(i,n) = x $时,必然$x|n$. 所以我们枚举一下n的约数,对于每个约数x,显然$ ...
- ubuntu18.04 安装hadoop 2.7.3+hive 2.3.4
1. 安装hadoop 详细请参见本人的另外一片博文<Hadoop 2.7.3 分布式集群安装> 2. 下载hive 2.3.4 解压文件到/opt/software -bin.tar.g ...
- ECharts之饼图和柱形图demo
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- MIT提出精细到头发丝的语义分割技术,打造效果惊艳的特效电影
来自 MIT CSAIL 的研究人员开发了一种精细程度远超传统语义分割方法的「语义软分割」技术,连头发都能清晰地在分割掩码中呈现.在对比实验中,他们的结果远远优于 PSPNet.Mask R-CNN. ...
- 学习MongoDB 八: MongoDB索引(索引限制条件)(二)
一.简介 我们上一篇介绍了索引基本操作,通过db.collection.createIndex(keys, options)语法创建索引,我们继续介绍地理空间索引.索引的限制,使我们在MongoDB时 ...
- lb集群lvs的3种模式
Cluster原理 集群的总类: 1.负载均衡集群(LB:Load Banlancing):实现将一个访问量或者任务量特别大的应用,给他 平均分配到不同的服务器上面,以提供高容量.大并发. 2.高可用 ...
- smyfony2-curd-数据库创建
1创建类