public class httpClientStuParam06Test {
@Test
public void getParam() throws URISyntaxException {
System.out.println("测试httpClient配置");
CloseableHttpClient httpClient = HttpClients.createDefault();
URIBuilder uriBuilder = new URIBuilder("http://yun.itheima.com/search");
uriBuilder.setParameter("keys", "Java").setParameter("login", "张三同学");
HttpGet httpGet = new HttpGet(uriBuilder.build());
System.out.println("http请求信息:"+httpGet);
CloseableHttpResponse response=null;
try {
response= httpClient.execute(httpGet);
if(response.getStatusLine().getStatusCode()==200){
String content = EntityUtils.toString(response.getEntity(), "utf8");
System.out.println("响应得到内容长度为:"+content.length());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
原文链接 www.cnblogs.com/asplover/p/…