【问题标题】:How to follow the redirect in rest assured?如何放心地遵循重定向?
【发布时间】:2017-07-17 18:45:46
【问题描述】:

我有一个 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());  
    }

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

【问题讨论】:

    标签: rest-assured


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      尝试使用 IP 地址代替 URL 中的“localhost”。

      【讨论】:

        猜你喜欢
        • 2015-03-01
        • 2014-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-27
        • 2017-02-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多