John Gaby wrote:
> I am trying to figure out how to make HTTP get requests.  The
> following is what I have so far:
> 
>               HttpGet get = new HttpGet("http://www.microsoft.com";);
>               HttpClient client = new DefaultHttpClient();
>               HttpResponse response;
> 
>               try
>               {
>                       response = client.execute(get);
> 
>                       HttpEntity      entity  = response.getEntity();
> 
>                       InputStream stream = entity.getContent();
> 
>                       byte[] b = new byte[1000];
> 
>                       stream.read(b);
>               }
>               catch (ClientProtocolException e)
>               {
>               }
>               catch (IOException e)
>               {
>               }
> 
> This works fine, but what I really need is a way to read the data
> asynchronously.  Is there some way to set up the transfer and specify
> a call back function which is called as the bytes come in, or do I
> need to create a thread to do this?

HttpClient tends to be used synchronously. It works great with an AsyncTask:

http://github.com/commonsguy/cw-android/tree/master/Service/WeatherPlus/

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 2.0 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to