如何放心的跟随重定向?
How to follow the redirect in rest assured?
我有一个 spring 引导应用程序,控制器将根据 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());
}
我在响应中收到 302 和重定向页面的位置 header。
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
我遇到了类似的问题,状态代码为 302 和 307 的 "post" 不支持放心重定向。我们必须使用 303 状态代码更改为 "get" 或 "post"。更多信息点击here
尝试使用 IP 地址代替 URL 中的 "localhost"。
我有一个 spring 引导应用程序,控制器将根据 post 参数重定向到一个页面。
我正在创建要断言重定向页面的测试用例
但是我没能从放心的响应
@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());
}
我在响应中收到 302 和重定向页面的位置 header。
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
我遇到了类似的问题,状态代码为 302 和 307 的 "post" 不支持放心重定向。我们必须使用 303 状态代码更改为 "get" 或 "post"。更多信息点击here
尝试使用 IP 地址代替 URL 中的 "localhost"。