我在访问paypal(沙盒)API时遇到问题。代码
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
HTTPBuilder http = new HTTPBuilder( 'https://api.sandbox.paypal.com/v1' )
http.auth.basic clientId, secret
http.headers.Accept = 'application/json'
http.headers[ 'Accept-Language' ] = 'en_US'
http.request( POST ){
uri.path = '/oauth2/token'
requestContentType = URLENC
body = 'grant_type=client_credentials'
response.success = { resp, json ->
println json
}
}
在我的本地计算机上提供
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
如果我运行curl
curl -v https://api.sandbox.paypal.com/v1/oauth2/token -H "Accept: application/json" -H "Accept-Language: en_US" -H "Authorization: Basic {base64 text}=" -d "grant_type=client_credentials"
我明白了:
curl: (35) error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
如果我在Postman
中运行相同的查询,它会顺利运行。
我错过了什么?
更新:
如果我添加-Djavax.net.debug=ssl:handshake
,则会显示以下调试信息
http-bio-8880-exec-3,WRITE:TLSv1握手,长度= 149 http-bio-8880-exec-3,READ:TLSv1 Alert,length = 2 HTTP-BIO-8880-EXEC-3 ,RECV TLSv1警告:
致命, handshake_failure http-bio-8880-exec-3,名为closeSocket() http-bio-8880-exec-3,处理异常:javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure