gpt4 book ai didi

rest-assured - 如何放心地跟随重定向?

转载 作者:行者123 更新时间:2023-12-04 05:30:23 24 4
gpt4 key购买 nike

我有一个 Spring Boot 应用程序,一个 Controller 将根据 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());
}

我在响应 header 中收到 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

最佳答案

我遇到了类似的问题,放心重定向不支持状态代码为 302 和 307 的“发布”。我们必须使用 303 状态代码更改为“获取”或“发布”。更多信息点击here

关于rest-assured - 如何放心地跟随重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42480929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com