java HttpClient 4.3.6的jar包
为什么我get post 请求中文乱码
还有怎么请求的时候怎么带参数,我这样写有什么问题没有,现在的情况就是乱码
public static void get() {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://api.a.7xz.com/v140/ceshi");
httpget.addHeader(new BasicHeader("npi", "3"));
// httpget.addHeader("", "");
CloseableHttpResponse httpReponse = httpClient.execute(httpget);
try {
System.out.println(httpReponse.getStatusLine());
HttpEntity entity = httpReponse.getEntity();
System.out.println(EntityUtils.toString(entity));
} finally {
httpReponse.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void post() {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://api.a.7xz.com/v140/ceshi");
List<BasicNameValuePair> Listnvps = new ArrayList();
Listnvps.add(new BasicNameValuePair("npi", "3"));
httpPost.setEntity(new UrlEncodedFormEntity(Listnvps, "UTF-8"));
CloseableHttpResponse httppHttpResponse2 = httpClient
.execute(httpPost);
try {
System.out.println(httppHttpResponse2.getStatusLine());
System.out.println(EntityUtils.toString(httppHttpResponse2
.getEntity()));
} finally {
httppHttpResponse2.close();
}
httpClient.close();
} catch (Exception e) {
e.printStackTrace();
}
}