views:

447

answers:

2

Hi

I have this code on my Android phone.

   URI uri = new URI(url);
   HttpPost post = new HttpPost(uri);
   HttpClient client = new DefaultHttpClient();
   HttpResponse response = client.execute(post);

I have a asp.net webform application that has in the page load this

 Response.Output.Write("It worked");

I want to grab this Response from the HttpReponse and print it out. How do I do this?

I tried response.getEntity().toString() but it just seems to print out the address in memory.

Thanks

+2  A: 

Use ResponseHandler. One line of code. See here and here for sample Android projects using it.

CommonsWare
which android api version does this become available at? I might have to rewrite come code :D
Tom Dignan
I think it's been there since the beginning, or at least since Android 0.9. It's part of the standard HttpClient 4.x package.
CommonsWare
A: 

I would just do it the old way. It's a more bulletproof than ResponseHandler, in case you get different content types in the response.

ByteArrayOutputStream outstream = new ByteArrayOutputStream();
response.getEntity().writeTo(outstream);
byte [] responseBody = outstream.toByteArray();