问题:restAssured,访问SSL网站报错,提示:
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target。
解决:
//忽略HTTPS校验
RestAssured.useRelaxedHTTPSValidation();
来源:官网 (https://github.com/rest-assured/rest-assured/wiki/Usage)
中有
SSL
In most situations SSL should just work out of the box thanks to the excellent work of HTTP Builder and HTTP Client. There are however some cases where you'll run into trouble. You may for example run into a SSLPeerUnverifiedException if the server is using an invalid certificate. The easiest way to workaround this is to use "relaxed HTTPs validation". For example:
given().relaxedHTTPSValidation().when().get("https://some_server.com"). ..
You can also define this statically for all requests:
RestAssured.useRelaxedHTTPSValidation();
or in a request specification.
This will assume an SSLContext protocol of SSL
. To change to another protocol use an overloaded versionen of relaxedHTTPSValidation
. For example:
given().relaxedHTTPSValidation("TLS").when().get("https://some_server.com"). ..