我有一个spring boot应用程序,控制器将根据post参数重定向到页面。
我正在创建要断言重定向页面的测试用例,但是我无法从放心的响应中获取重定向的html
@Test
public void test() throws Exception {
Response response = given()
.param("name", "myName")
.when()
.redirects().follow(true).redirects().max(100)
.post("/myPath"); // it will redirect to another page
// I want to print from <html> to </html> of the redirected page
System.out.println("returned full html /n" + response.getBody().asString());
}
Run Code Online (Sandbox Code Playgroud)
我收到302以及重定向页在响应标头中的位置。
11:38:03.291 [main] DEBUG org.apache.http.headers - << "Location: http://localhost:8080/myRedirectPage[\r][\n]"
.........
11:38:03.291 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 302
11:38:03.291 [main] DEBUG org.apache.http.headers - << HTTP/1.1 302
Run Code Online (Sandbox Code Playgroud)