使用 Rest Assured 获取重定向的 URL? [英] Get the url of a redirect with Rest Assured?

查看:45
本文介绍了使用 Rest Assured 获取重定向的 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a GET request which then makes a 307 redirect to another URL and from there it makes another 302 redirect and so on till it gets to the requested page. I am having problems extracting the URL from the first redirect, the 307, I want to see the location where is redirected to. I am using Rest Assured as framework. Thanks!

推荐答案

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

I had the same problem, but I didn't have the 307, just 302. I imagine the solution would be the same. What I did was:

  1. 使用 redirects().follow(false)

从第一次重定向中获取 URL

capture the URL from the first redirect

再次调用以跟随重定向

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);

这篇关于使用 Rest Assured 获取重定向的 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆