A 302 response results in a StatusCode exception being thrown

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

A 302 response results in a StatusCode exception being thrown

Gerolf Seitz
Hi,

I want to access a cellphone network provider's customer service website with the following lines of code:

val http = new Http
var req = :/("www.drei.at") / "selfcare" / "login.do"
req = req.secure
val rform = req << Map("userName"->"CELL_NUMBER", "password"->"PASSWORD")
http(rform >~ { _.getLines.foreach(println) })

The last line results in an exception (StatusCode 302) being thrown.
The actual response has an HTTP Status 302, redirecting to another page: https://www.drei.at/selfcare/restricted/prepareCustomerzoneHome.do

Do I need to configure HttpClient to take care of this?
A quick browse through Dispatch's code revealed that Dispatch itself only "likes" responses 200-204.

Any help is very much appreciated.
  Gerolf
Reply | Threaded
Open this post in threaded view
|

Re: A 302 response results in a StatusCode exception being thrown

n8han
Administrator
That's right, but the redirect should not by bubble up that far. I bet the HTTP client defaults are different for secure connections...
Nathan

"Gerolf Seitz [via Databinder]" <[hidden email]> wrote:

>
>
>
>Hi,
>
>I want to access a cellphone network provider's customer service website
>with the following lines of code:
>
>val http = new Http
>var req = :/("www.drei.at") / "selfcare" / "login.do"
>req = req.secure
>val rform = req << Map("userName"->"CELL_NUMBER", "password"->"PASSWORD")
>http(rform >~ { _.getLines.foreach(println) })
>
>The last line results in an exception (StatusCode 302) being thrown.
>The actual response has an HTTP Status 302, redirecting to another page:
>https://www.drei.at/selfcare/restricted/prepareCustomerzoneHome.do
>
>Do I need to configure HttpClient to take care of this?
>A quick browse through Dispatch's code revealed that Dispatch itself only
>"likes" responses 200-204.
>
>Any help is very much appreciated.
>  Gerolf
>
>______________________________________
>View message @ http://databinder.3617998.n2.nabble.com/A-302-response-results-in-a-StatusCode-exception-being-thrown-tp5331361p5331361.html
>To start a new topic under Databinder, email [hidden email]
>To unsubscribe from Databinder, click http://databinder.3617998.n2.nabble.com/subscriptions/Unsubscribe.jtp?code=bmF0aGFuQHRlY2huaWNhbGx5LnVzfDM2MTc5OTh8MjUyOTkwMzc4

Reply | Threaded
Open this post in threaded view
|

Re: A 302 response results in a StatusCode exception being thrown

Gerolf Seitz
Hm, I'll try out a few things.
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: A 302 response results in a StatusCode exception being thrown

Gerolf Seitz
In reply to this post by n8han
Explicitly setting the HttpClientParams "handle_redirects" and "cookie_policy" didn't help :/

Btw, I get the same behavior for non SSL requests too.

  Gerolf
Reply | Threaded
Open this post in threaded view
|

Re: A 302 response results in a StatusCode exception being thrown

n8han
Administrator
That's surprising. I've tested it against a number of 302 redirects and it works; I wonder what is different about this one.

One thing that *will* work is to process the redirect yourself. There's an example of handling 404 responses with the `x` method:

http://github.com/n8han/Databinder-Dispatch/blob/master/http/src/test/scala/HttpSpec.scala#L51

There's also some examples in there of getting headers out while applying a second response handler. That should get you there. If the the redirect is expected, it might be best to do things a differently from that and call `when` to require that the first request return a 302, process the Location header, then get the data you want in the next request.

Nathan


On 7/23/10 3:52 PM, Gerolf Seitz [via Databinder] wrote:
Explicitly setting the HttpClientParams "handle_redirects" and "cookie_policy" didn't help :/

Btw, I get the same behavior for non SSL requests too.

  Gerolf