簡體   English   中英

如何在 RestAPI 中獲取 GET 調用的響應體?

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

我是 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
}

使用body()方法來訪問響應的正文。

響應對象中有多個字段,如正文、標題、狀態代碼、cookie 等,請在此處查看完整的 java 文檔。

您的代碼的答案是調用getResponseWithGetMethod().body()getResponseWithGetMethod().asString() 以后可能適合你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM