放心收到 SSL 错误

问题描述 投票:0回答:2

我正在致力于使用“放心”来自动化 API 测试。我有一个 API,如果我们使用 http 调用该 API,那么服务器将返回响应代码 302 和位置相同的 URL,但使用 https 。 我写了下面的代码:

RequestSpecification httprequest= RestAssured.given().relaxedHTTPSValidation();
Response response= httprequest.request(Method.GET, uri);

执行上述操作时,系统抛出错误

javax.net.ssl.SSLHandshakeException

我已经搜索了很多,但没有找到合适的解决方案。

java rest rest-assured
2个回答
2
投票

我也曾因“放心”而感到头痛。我不确定您是否给了我们足够的信息,但据我所知,您正在使用宽松的 HTTPS 验证进行 HTTPS 调用,但您的 API 正在强制执行 SSL。当您通过 HTTP 发送时它会起作用,因为它无论如何都不安全并且不强制执行安全性。尝试像这样运行 HTTPS:

RequestSpecification httprequest= RestAssured.given();
Response response= httprequest.request(Method.GET, uri);

仅当您有意尝试不安全的连接并希望像使用自签名证书或 http 一样绕过警告时,才需要

.relaxedHTTPSValidation()


0
投票

在您的脚本中实现“useRelaxedHTTPSValidation”,如下所示

RestAssured.baseURI = "https://jsonplaceholder.typicode.com"; RestAssured.useRelaxedHTTPSValidation();

  String response = given()
        
        .header("Content-Type", "application/json")
        .log().body()
        .body(Payload.addPayload())
    .when()
        .post("/posts")
    .then()
        .assertThat()
        .log().all()
        .statusCode(201).extract().response().asString();
© www.soinside.com 2019 - 2024. All rights reserved.