|
@ -70,42 +70,6 @@ public class HttpClientUtil {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public static String post(String url, List<NameValuePair> params, String chatSet,String userAgent) {
|
|
|
// 创建默认的httpClient实例.
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
// 创建httppost
|
|
|
HttpPost httppost = new HttpPost(url);
|
|
|
UrlEncodedFormEntity uefEntity;
|
|
|
try {
|
|
|
uefEntity = new UrlEncodedFormEntity(params, chatSet);
|
|
|
httppost.setEntity(uefEntity);
|
|
|
httppost.setHeader("user-agent",userAgent);
|
|
|
CloseableHttpResponse response = httpclient.execute(httppost);
|
|
|
try {
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
if (entity != null) {
|
|
|
return EntityUtils.toString(entity, chatSet);
|
|
|
}
|
|
|
} finally {
|
|
|
response.close();
|
|
|
}
|
|
|
} catch (ClientProtocolException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
|
e1.printStackTrace();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
// 关闭连接,释放资源
|
|
|
try {
|
|
|
httpclient.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* http post调用方法
|
|
|
* @param url
|