Reading response into a variable

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

Reading response into a variable

parsa28
Dear all,

I'm stuck at a very basic task which is to get the output of http() as string and put it into a variable. How can I achieve that?

Cheers,
Parsa
Reply | Threaded
Open this post in threaded view
|

Re: Reading response into a variable

n8han
Administrator
On 10/24/2010 11:11 AM, parsa28 [via Databinder] wrote:
> I'm stuck at a very basic task which is to get the output of http() as
> string and put it into a variable. How can I achieve that?

There's a method `as_str` on Response for this purpose:
http://sourced.implicit.ly/net.databinder/dispatch-http/0.7.7/dispatch/Http.scala.html#19489

If you follow the stdout walkthrough:
http://dispatch.databinder.net/Stdout_Walkthrough

Instead of piping the response body to stdout, you could retain it in a
string (assuming it fits in memory) like this:

val page = http("http://databinder.net/dispatch/Stdout_Walkthrough" as_str)

Nathan
Reply | Threaded
Open this post in threaded view
|

Re: Reading response into a variable

parsa28
Thanks Nathan, for this reply and Dispatch in general. I love the fact that there's a new good thing everyday since I've started touching Scala.