我需要下载一个网页上的Android应用程序,我有一个很难决定是否使用Android的Apache HTTP客户端或Java的URLConnection的。
I need to download a web page on an android app and I am having a hard time deciding whether to use the android apache http client or java's URLConnection.
有什么想法?
对于大多数的事情,我会说,的HttpClient
是要走的路。但也有一些情况和边缘情况下,我会回落到一个的URLConnection
。边缘的案例,here和here
For most things I'd say that HttpClient
is the way to go. However there are some situations and edge cases where I'd fall back to a URLConnection
. Examples of edge cases here and here
修改
类似的问题已经被问过:的HttpClient VS HttpURLConnection的。 我会假设,的HttpURLConnection
是稍快为的HttpClient
是建立在标准的Java库的顶部。然而我会找到的HttpClient
code更快,更容易编写和维护。根据以下意见,的HttpClient
的核心要素已经性能进行了优化。
EDIT
A similar question has been asked before: httpclient vs httpurlconnection. I would assume that HttpUrlConnection
is somewhat faster as the HttpClient
is built on top of the standard Java libraries. However I would find HttpClient
code much quicker and easier to write and maintain. According to a comments below, the core elements of HttpClient
have been performance optimised.
如果性能是一个大问题最好的办法是写两个客户,一个使用每一种方法,那么标杆他们两个。如果你这样做,请让我们知道结果。
If performance is a major concern your best bet is to write two clients, one using each method, then benchmark them both. If you do this, please let us know the results.