HttpClient 在本地tomcat中可以发起访问,但是部署到线上环境就无法访问!!!

发布于 2021-11-22 14:58:12 字数 1636 浏览 859 评论 1

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 这里。

这个是服务器屏蔽了吗?如何解决啊?求大神帮忙。。。。


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2021-11-24 02:10:33

顶啊...快来人..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文