HttpClient 版本4.3.1
private static HttpClient httpClient;
static {
httpClient = HttpClients.custom().setSSLSocketFactory(MySSLConnectionSocketFactory.getInstance()).build();
}
private static String getLoginResult() throws UnsupportedEncodingException, IOException {
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
formParams.add(new BasicNameValuePair("userName", "testAccount");
formParams.add(new BasicNameValuePair("password","password");
HttpEntity entity = new UrlEncodedFormEntity(formParams, "UTF-8");
return HttpUtil.requestPost(LOGIN_URL, entity);
}
public static String requestPost(String url, HttpEntity entity) throws IOException {
HttpPost httpPost = new HttpPost(url);httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
return EntityUtils.toString(httpResponse.getEntity(), ContentType.get(entity).getCharset());
}
HttpClient 做了饶过证书的处理。
在调用getLoginResult()方法时,在本地tomcat上跑是可以发起请求并能返回正确结果,但是发布到linux服务器上就会卡在 execute 这里。
这个是服务器屏蔽了吗?如何解决啊?求大神帮忙。。。。