【问题标题】:How to get response body of GET call in RestAPI?如何在 Rest API 中获取 GET 调用的响应体?
【发布时间】:2020-10-30 13:10:14
【问题描述】:

我是 API 测试新手。我想验证 GET 方法的响应正文。但它使用以下代码返回 io.restassured.internal.RestAssuredResponseImpl@35adf623。请让我知道我该如何解决这个问题。使用 POST 方法,它工作正常。使用提供的 GET 方法失败时,所有其他值都正确传递。

    public static Response getResponseWithGetMethod() throws Exception {
    Response response = RequestInvoker.invokeGET();
    return response;
}

输出:

io.restassured.internal.RestAssuredResponseImpl@35adf623

预期输出是:

 {
"path1": true,
"path2": true,
"path3": true
}

【问题讨论】:

  • 你得到的是一个对象。要么 jsonify response 要么向您的对象添加 toString() 方法(前提是您编写了看起来不太可能的类)

标签: java api get rest-assured


【解决方案1】:

使用body() 方法访问响应正文。

【讨论】:

    【解决方案2】:

    响应对象中有多个字段,如正文、标题、状态代码、cookie 等, 查看完整的 java 文档here

    您的代码的答案是调用getResponseWithGetMethod().body()getResponseWithGetMethod().asString();以后可能适合你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-02
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多