本文介绍了Apache的HTTP客户端或URLConnection的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要下载一个网页上的Andr​​oid应用程序,我有一个很难决定是否使用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和<一href="http://stackoverflow.com/questions/4330392/on-android-make-a-post-request-with-url-en$c$cd-form-data-without-using-urlencod/4794289#4794289">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 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.

这篇关于Apache的HTTP客户端或URLConnection的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 03:52