Is it possible to get a redirect URL from a response?

4,725 views
Skip to first unread message

Ilyas Patel

unread,
Mar 16, 2016, 1:20:10 PM3/16/16
to REST assured
I'm making a http GET request which performs 3 redirects. There is some information appended to the redirectURL which I need to capture. Is this possible?

The request I am making:

.given()
.redirects()
.follow(true)
.cookie("value", session)
.when()
.get("https://www.example.com/v1/user/authorise");

I've checked the HTTP headers and there is no location header. I have seen another example using this from the java.net library:

URLConnection urlConn = myUrl.openConnection();
urlConn.getURL().toString();

Johan Haleby

unread,
Mar 17, 2016, 12:46:46 AM3/17/16
to rest-a...@googlegroups.com
If you want to redirect manually use the redirect dsl to disable redirects: given().redirects.follow(false). ..

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Filip Gudjevski

unread,
Mar 27, 2017, 10:35:24 AM3/27/17
to REST assured
Hi Johan,

I have a similar situation where I make a GET request to a certain URL,  that request is redirected with a 307 to another url, is there any way to get the "Location" from the first redirect?

Regards.

Johan Haleby

unread,
Mar 28, 2017, 1:49:06 AM3/28/17
to rest-a...@googlegroups.com
Can't you do given().redirects.follow(false).. and then extract the Location header?

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

filip.g...@cuponation.com

unread,
May 22, 2017, 4:01:37 AM5/22/17
to REST assured
Hi Johan, one question regarding rest assured redirects, when I set .redirect(redirectConfig().followRedirects(false)) - it doesn't actually make the redirect or it just means that the rest assured api stops following it? I am asking this because I have a couple of redirects which I don't want to happen all the way due to SEO statistics, I just need the first one. It works like this and in output it shows only the response from the first redirect where it stops, but is that only for the API or it doesn't go all the way to the page.

Thanks

Johan Haleby

unread,
May 22, 2017, 4:35:28 AM5/22/17
to rest-a...@googlegroups.com
On Mon, May 22, 2017 at 9:39 AM, <filip.g...@cuponation.com> wrote:
Hi Johan, one question regarding rest assured redirects, when I set .redirect(redirectConfig().followRedirects(false)) - it doesn't actually make the redirect or it just means that the rest assured api stops following it?

Hmm I don't understand what the difference would be?
 
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

filip.g...@cuponation.com

unread,
May 22, 2017, 5:53:05 AM5/22/17
to REST assured
Well I currently have:

protected RequestSpecification spec() {
RestAssuredConfig restAssuredConfig = RestAssuredConfig.config()
.redirect(redirectConfig().followRedirects(false))
.objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(
(aClass, s) -> new ObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
));
 
and it does not follow the redirects in the Rest Assured API i.e the output shows only the response from the first request which is what I need and it's great. My question is does the followRedirects rule means that it doesn't make the redirects at all or I am not seeing the results from the redirects in the output. I am testing an application where I only have to test if the first redirect is made and to not actually go to the landing page because it can mess up the SEO statistics. 

Hope I was clearer :)

Thanks

Johan Haleby

unread,
May 23, 2017, 1:15:30 AM5/23/17
to rest-a...@googlegroups.com
It shouldn't make the redirect request at all.

/Johan

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages