2017-09-25 62 views
0

试图寻找我们的博客,但没有能够找到一些指针,以便张贴,Regd httpclient.executeMethod(request);抛出IOException的服务器,而运行在本地日食

我只是在httpsClient Post方法的代码工作如下,面向IOException。小指针可能会帮助,不需要详细的答案。

HttpClient httpclient = new HttpClient();   
       request = new PostMethod("https://ref.net/auth/token?grant_type=password");    
       request.setRequestHeader("Authorization", "Basic KolokYrZTo="); 
       request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 

      NameValuePair[] data = { 
        new NameValuePair("username", "abc"), 
        new NameValuePair("password", "123"), 
        new NameValuePair("grant_type", "password"), 
      }; 

      request.setRequestBody(data); 
      httpclient.executeMethod(request); 
} catch (IOException e) { 
        e.printStackTrace(); 
        logger.error("IOException in post()...."+e.getMessage());     
       } 

我正在与公地HttpClient的月食这个代码3.1.jar它运行完全正常,但是当我在我的代码移动到服务器,并尝试运行相同的代码,该httpclient.executeMethod(request);抛出IOException异常。令我惊讶的是e.printStackTrace();不打印为e对象本身是null 我如何捕获这个异常并调试这个,我在这里做错了什么。

在我本地我有Java1.8但运行在编译器合规性级别 1.6-在服务器上。我试着运行1.8和1.6相同的错误。

+0

它是否与一些证书有关,我们可能需要在服务器上进行配置,并且存在于本地?,但我没有添加任何证书 –

+0

如果您说'e'真的是'null',那么整个事情应该随后在执行'e.printStackTrace'时抛出一个'NullPointerException',所以我怀疑这确实是这种情况。我假设你指的是你在日志中看到的内容。但是,您只需添加可能为null的'e.getMessage()'。记录完整的异常(因此抛出的异常类型和堆栈跟踪也会记录下来),并将其添加到此处,以便对您的问题进行更多描述。 – Lothar

+0

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到有效的证书路径,请求目标 at sun.security.ssl.Alerts .getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1937) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) –

回答

0

随着您作为评论添加的错误消息清楚了这里发生了什么。您要连接的服务器正在使用您在命令外壳上使用的JVM不知道的服务器证书。

如果您搜索与commons httpclient相结合的此错误消息,您可以找到几页讨论此问题,例如,一个在StackOverflow

相关问题