简体   繁体   English

如何在 RestAPI 中获取 GET 调用的响应体?

[英]How to get response body of GET call in RestAPI?

Am new to API testing.我是 API 测试的新手。 I wanted to validated the response body of the GET method.我想验证 GET 方法的响应主体。 But it is returning the io.restassured.internal.RestAssuredResponseImpl@35adf623 with the below code.但它使用以下代码返回 io.restassured.internal.RestAssuredResponseImpl@35adf623 。 Please let me know how can I resolve this.请让我知道我该如何解决这个问题。 With POST Method, it works fine.使用 POST 方法,它工作正常。 Failing with GET method provided am passing all other values correct.提供的 GET 方法失败正在传递所有其他正确的值。

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

Output :输出 :

io.restassured.internal.RestAssuredResponseImpl@35adf623

Expected output is :预期输出是:

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

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

Response object has multiple fields in it like, body, headers, status code, cookies etc., Check out the complete java doc here .响应对象中有多个字段,如正文、标题、状态代码、cookie 等,请在此处查看完整的 java 文档。

Answer to your code is to call getResponseWithGetMethod().body() or getResponseWithGetMethod().asString() ;您的代码的答案是调用getResponseWithGetMethod().body()getResponseWithGetMethod().asString() later one might be appropriate for you.以后可能适合你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM