get方式调用http接口 Header赋参数值
/**
195. * 发送 get请求
196. */
public static void get() {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
// 创建httpget.
HttpGet httpget = new HttpGet("
http://211.156.193.140:8002/cotrackapi/api/track/mail/1104389559880");
httpget.setHeader("authenticate", "sdgszzswsgp_xiangmu123456");
httpget.setHeader("version", "ems_track_cn_1.0");
httpget.setHeader("Accept-Charset", "ISO8859-1");
// System.out.println("executing request " + httpget.getURI());
// 执行get请求.
CloseableHttpResponse response = httpclient.execute(httpget);
try {
// 获取响应实体
HttpEntity entity = response.getEntity();
// System.out.println("--------------------------------------");
// 打印响应状态
/// System.out.println(response.getStatusLine());
if (entity != null) {
// 打印响应内容长度
// System.out.println("Response content length: " + entity.getContentLength());
// 打印响应内容
String jsmc=EntityUtils.toString(entity);
System.out.println("Response content: " + jsmc);
String jsmc1=new String(jsmc.getBytes("ISO-8859-1"),"GBK");
System.out.println("------------------------------------"+jsmc1);
String jsmc2=new String(jsmc.getBytes("ISO-8859-1"),"utf-8");
System.out.println("------------------------------------"+jsmc2);
// String jsmc1=new String(jsmc.getBytes("ISO-8859-1"),"GBK");
// System.out.println("------------------------------------"+jsmc1);
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
195. * 发送 get请求
196. */
public static void get() {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
// 创建httpget.
HttpGet httpget = new HttpGet("

httpget.setHeader("authenticate", "sdgszzswsgp_xiangmu123456");
httpget.setHeader("version", "ems_track_cn_1.0");
httpget.setHeader("Accept-Charset", "ISO8859-1");
// System.out.println("executing request " + httpget.getURI());
// 执行get请求.
CloseableHttpResponse response = httpclient.execute(httpget);
try {
// 获取响应实体
HttpEntity entity = response.getEntity();
// System.out.println("--------------------------------------");
// 打印响应状态
/// System.out.println(response.getStatusLine());
if (entity != null) {
// 打印响应内容长度
// System.out.println("Response content length: " + entity.getContentLength());
// 打印响应内容
String jsmc=EntityUtils.toString(entity);
System.out.println("Response content: " + jsmc);
String jsmc1=new String(jsmc.getBytes("ISO-8859-1"),"GBK");
System.out.println("------------------------------------"+jsmc1);
String jsmc2=new String(jsmc.getBytes("ISO-8859-1"),"utf-8");
System.out.println("------------------------------------"+jsmc2);
// String jsmc1=new String(jsmc.getBytes("ISO-8859-1"),"GBK");
// System.out.println("------------------------------------"+jsmc1);
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
本文原创,转载必追究版权。