6

I am using httparty to send a get request and then trying to follow the redirect:

get 'https://accounts.google.com/o/oauth2/auth'

how can i follow the redirect using HTTParty?

sorry if this have been asked before, but i could not find the answer anywhere.

Thanks

Wahtever
  • 3,597
  • 10
  • 44
  • 79

2 Answers2

8

Probably it's not needed now, but for someone who need.

From documentation, there is special option for automatically redirects

follow_redirects(value = true) ⇒ Object

Proceed to the location header when an HTTP response dictates a redirect. Redirects are always followed by default.

So you can use this options like that:

HTTParty.get('http://google.com', follow_redirects: true)
Farkhat Mikhalko
  • 3,565
  • 3
  • 23
  • 37
0

Guessing this is a little out of date now, what with the question being about a month old... but my understanding of the HTTParty docs is that it should automatically follow redirects, unless you set the no_follow flag. I haven't successfully tested it though (I'm a total HTTParty n00b and stumbled on this trying to find an answer to my own problem, d'oh...)

If that doesn't work, you could always read the header directly and parse the redirect manually. I've done that in Javascript AJAX requests before, it is not difficult. But you shouldn't have to do that with HTTParty.

user435779
  • 413
  • 4
  • 15
  • I had to actually construct the url and redirect manually, that's the only way it worked. – Wahtever May 14 '13 at 20:49
  • It doesn't look like it follows redirects if the response code is `200` and if it uses a `meta` tag redirect instead. – Hengjie Oct 10 '13 at 00:24