当我通过response.getBody().asString()
将 JSON 正文转换为字符串时,它会丢失 JSON 响应中的换行符。如何保留它们并显示在控制台输出中?
如果我使用简单的GET请求来获取一些JSON数据,它已经美化了视图
import io.restassured.RestAssured;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.testng.annotations.Test;
public class Demo6_GET_AuthTest
{
@Test
public void AuthTest()
{
RestAssured.baseURI = "https://test.sideways6.com/api/";
RequestSpecification httprequest = RestAssured.given();
Response response = httprequest.request(Method.POST, "auth/login");
String responseBody = response.getBody().asString();
System.out.println(responseBody);
}
}
输出示例
打印为字符串不会美化响应,
尝试 System.out.println(response.then((.log((.all(((;