【问题标题】:Get the url of a redirect with Rest Assured?使用 Rest Assured 获取重定向的 url?
【发布时间】:2017-08-20 07:38:31
【问题描述】:

我正在发出 GET 请求,然后将 307 重定向到另一个 URL,然后从那里进行另一个 302 重定向,依此类推,直到到达请求的页面。我在从第一个重定向 307 中提取 URL 时遇到问题,我想查看重定向到的位置。我正在使用 Rest Assured 作为框架。谢谢!

【问题讨论】:

    标签: java redirect http-redirect rest-assured http-status-code-307


    【解决方案1】:

    我有同样的问题,但我没有 307,只有 302。我想解决方案是一样的。我所做的是:

    1. 在第一次调用redirects().follow(false)时停止跟踪重定向

    2. 从第一个重定向中捕获 URL

    3. 再次调用以跟随重定向

      Response resp1 =
              given().
                  contentType(ContentType.URLENC).
                  body("AUTH_TOKEN=&j_username=" + encodedUsername + "&j_password=" + password + "&userName=&AUTH_TOKEN=").
                  redirects().follow(false).
              expect().
                  statusCode(302).
              when().
                  post("/authenticate/j_spring_security_check");
      
      String headerLocationValue = resp1.getHeader("Location");
      
      Response resp2 =
              given().
                  cookie(resp1.getDetailedCookie("JSESSIONID")).
              expect().
                  statusCode(200).
              when().
                  get(headerLocationValue);
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 2017-09-07
      • 2012-10-04
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多