Swagger Get API return HTML 用于使用 RestAssured 而不是 JSON 响应构建静态分发包。适用于 CURL

Swagger Get API return HTML for static distribution bundle build using RestAssured instead of JSON Response. Works fine with CURL

遇到一个问题,我在使用 RestAssured 验证 Swagger BookStore 上的一个 GET 调用时遇到了问题 API。它在 Curl 中运行良好。

有效的 CURL 命令:

curl -X GET “https://bookstore.toolsqa.com/Account/v1/User/f00600d9-dc34-46e7-84f1-9404410b7f74” -H “accept: application/json” -H “authorization: Basic Qm9va1Rlc3RlcjEyOlRlc3RlciMxMg==”

并且它 returns JSON 响应符合预期。

现在,我使用 RestAssured 调用相同的 API,代码如下:

RestAssured.given().header(“accept”, “application/json”)
.header(“authorization”, “Basic Qm9va1Rlc3RlcjpUZXN0ZXIjMTI=”)
.when()
.get(“https://bookstore.toolsqa.com/Account​/v1​/User​/5641c9d9-1e3f-45be-a752-e1cc9d31e151”);

但它没有给出任何 JSON 响应,而是 HTML 默认页面。

也许您的代码包含 'ZWSP​​' 但您在 IDE 上看不到它。

我在将您的代码复制到 Intellij 时看到了它。删除这些,代码运行正常。

RestAssured.given().header("accept", "application/json")
        .header("authorization", "Basic Qm9va1Rlc3RlcjpUZXN0ZXIjMTI=")
        .when()
        .get("https://bookstore.toolsqa.com/Accoun/v1/User/5641c9d9-1e3f-45be-a752-e1cc9d31e151")
        .prettyPrint();