Grails:Groovy:SSLPeerUnverifiedException: peer not authentic



我想在我的本地系统中运行代码时,将xml请求打到url,它工作良好,我创建了一个war文件并在服务器中部署了相同的文件,但在服务器中运行时获得异常'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated'我已经使用了groovy HTTP builder

def http = new HTTPBuilder(url)
          http.auth.basic('username', 'password')
        try {               
            http.request(Method.POST, ContentType.TEXT) {
                        req->
                            headers.accept = "application/xml"
                            body = request //xml request
                            response.success = {
                                        resp,reader ->
                                            Response =  reader.text
                            }
            }
        }
        catch(HttpResponseException ex) {
             println ex;
        }
在这种情况下,我该如何解决这个问题?

解决方法:以下答案提供了解决此问题的方法:https://stackoverflow.com/a/25076888/782034

刚刚发现新版本(0.7.1)的HttpBuilder引入方法:

ignoreSSLIssues()

这解决了所有关于无效SSL证书的问题(当然你必须意识到它也会降低安全性)。

关于此方法的更多信息:http://groovy.codehaus.org/modules/http-builder/doc/ssl.html(部分在底部)

def http = new HTTPBuilder(url)
http.ignoreSSLIssues()

解决方案:如果您想以"正确"的方式做事,请检查有关导入服务器证书的其他解决方案。例如SSLPeerUnverifiedException: peer not authenticated

如果您使用ignoreSSLIssues()但仍然得到相同的异常

在Gradle/Maven中添加最新的httpclient

编译"org.apache.httpcomponents: httpclient: 4.5.3"

最新更新