I have tried to call out to the web using both HttpClient and
URLConnection, and I get "unknown error" in both cases at the point
the call is actually made (HttpClient.execute() or
URLConnection.getContent() methods). My emulator is able to connect
to the web, because I can use the Browser with no problem. So, I'm
assuming that there aren't any issues with my settings (this is being
done on my home network with no proxy server). Is there a "best
practices" preference between using HttpClient or URLConnection, and
are there any examples or sample apps (with source code) that make
simple calls to the web?
Make sure you have the "android.permission.INTERNET" Uses Permission
in your AndroidManifest.xml file to enable your app to access the
internet.
I don't know of any preference between HttpClient and URLConnection
(I'd also be happy to know if one of them is preferred).
There's an apps-for-android project which contains app samples created
by Google's Android team. I haven't examined them in-depth, but I'm
sure they have some pretty good usage examples. From just a quick
browse, this class might be a useful reference for you:
> I have tried to call out to the web using both HttpClient and
> URLConnection, and I get "unknown error" in both cases at the point
> the call is actually made (HttpClient.execute() or
> URLConnection.getContent() methods). My emulator is able to connect
> to the web, because I can use the Browser with no problem. So, I'm
> assuming that there aren't any issues with my settings (this is being
> done on my home network with no proxy server). Is there a "best
> practices" preference between using HttpClient or URLConnection, and
> are there any examples or sample apps (with source code) that make
> simple calls to the web?
I have no best practice for you but concerning my usage:
* I only use HttpClient when I need to handle cookies.
* For REST API calls, I use URLConnection which is quite simple.
On Oct 9, 12:54 pm, Jasp182 <Jasp...@gmail.com> wrote:
> I have tried to call out to the web using both HttpClient and
> URLConnection, and I get "unknown error" in both cases at the point
> the call is actually made (HttpClient.execute() or
> URLConnection.getContent() methods). My emulator is able to connect
> to the web, because I can use the Browser with no problem. So, I'm
> assuming that there aren't any issues with my settings (this is being
> done on my home network with no proxy server). Is there a "best
> practices" preference between using HttpClient or URLConnection, and
> are there any examples or sample apps (with source code) that make
> simple calls to the web?
ensure that <uses-permission> is inside <manifest>, too, not inside <application>.
i've had problems using URLConnection directly - with short transfers i could reproducibly get "SOCKETLOG add_recv_stats 0" log error messages, accompanied by nothing being delivered to the Android app. i switched to using Socket or HttpClient, and everything worked fine. URLConnection should work though IMHO.
>Make sure you have the "android.permission.INTERNET" Uses Permission >in your AndroidManifest.xml file to enable your app to access the >internet.
>I don't know of any preference between HttpClient and URLConnection >(I'd also be happy to know if one of them is preferred).
>There's an apps-for-android project which contains app samples created >by Google's Android team. I haven't examined them in-depth, but I'm >sure they have some pretty good usage examples. From just a quick >browse, this class might be a useful reference for you:
>On Oct 9, 12:54 pm, Jasp182 <Jasp...@gmail.com> wrote: >> I have tried to call out to the web using both HttpClient and >> URLConnection, and I get "unknown error" in both cases at the point >> the call is actually made (HttpClient.execute() or >> URLConnection.getContent() methods). My emulator is able to connect >> to the web, because I can use the Browser with no problem. So, I'm >> assuming that there aren't any issues with my settings (this is being >> done on my home network with no proxy server). Is there a "best >> practices" preference between using HttpClient or URLConnection, and >> are there any examples or sample apps (with source code) that make >> simple calls to the web?