- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我使用的是 Android 自带的 HttpComponents 库。我编写了 2 个类来使用 GET 和 POST 发送参数,并从服务器接收 InputStream 或 String。一切正常:每个线程上的下载、开始、暂停、恢复...但是今天我同时开始了两个下载,但都没有完成。
我用谷歌搜索了一个解决方案,我看到 Android 附带了 HttpCore 4.0-beta2。是的,它很旧了。它于 2008 年 7 月 1 日发布,Android 从那时起就没有更新过它......
我重写了我的类,但现在使用 HttpURLConnection,我可以同时下载两个文件。
好的,如果您正在考虑在 Android 上使用 HttpComponents,那是对您的警告。现在我的问题。我想将新版本 4.1 导入到我的项目中。我已将 jar 添加到构建路径,但现在如果新 (4.1) 和旧 (beta2、4.0) 包相同,我该如何使用这些 jar?
谢谢。
已解决
您必须使用 ThreadSafeClientConnManager 创建 DefaultHttpCLinet:
HttpParams parameters = new BasicHttpParams ();
HttpProtocolParams.setVersion (parameters, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset (parameters, HTTP.UTF_8);
HttpProtocolParams.setUseExpectContinue (parameters, false);
ConnManagerParams.setMaxTotalConnections (parameters, MAX_CONNECTIONS);
SchemeRegistry schReg = new SchemeRegistry ();
schReg.register (new Scheme ("http", PlainSocketFactory.getSocketFactory (), 80));
client = new DefaultHttpClient (new ThreadSafeClientConnManager (parameters, schReg), parameters);
更新:您还可以使用 AndroidHttpClient。使用此类,您无需使用 ThreadSafeClientConnManager
AndroidHttpClient client = AndroidHttpClient.newInstance ("Android");
最佳答案
But today I've started two downloads simultaneously none of them finished.
因为HttpClient默认不是线程安全的。您必须为此连接一个 ThreadSafeClientConnManager
。这包含在 HttpClient 中。文档。
I've googled a solution and I've seen that Android comes with HttpCore 4.0-beta2. Yes, it's very old. It was released on 01 July 2008 and Android hasn't updated it since then... and it's BUGGED
https://android.googlesource.com/platform/external/apache-http
请注意自“2008 年 7 月 1 日”以来有相当多的提交。
I've rewritten my classes but now using HttpURLConnection and I can download two files at the same time.
大多数程序员也可以使用 HttpClient 做到这一点。
how can I use these jars if the new (4.1) and the old (beta2, 4.0) packages are the same?
你不能。
关于java - 如何在 Android 上使用最新的 HttpComponents 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5154399/
我需要一些帮助,澄清如何将 HttpAsyncClient 与多部分实体一起使用。基本上,我正在尝试使用 HttpAsyncClient 将文件 (byte[]) 的内容上传为 MultiPart B
我有一个包含 HTTP header 的字符串。我想将其转换为 Apache HttpComponents HttpRequest 对象。有没有一种方法可以做到这一点,而无需自己拆开字符串? 本教程:
如何使 http 组件中的调试日志静音? 09:23:22.145 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selec
使用我在这里找到的代码:http://hc.apache.org/httpcomponents-client-ga/quickstart.html我创建了一个快速 HTTP 客户端应用程序。这是一个代
我正在尝试学习如何使用 Apache HttpComponents 发送 HttpResponse。我发现some examples在 Apache 网站上,但它们非常困惑且不清楚。 在下面的代码中,
我找不到任何关于 httpclient 4.1 的默认 httpParams 的文档? 执行 GET 时的默认套接字超时是多少? 最佳答案 根据documentation ,http.socket.t
我正在尝试将 Apache httpcomponents-client 库添加到我的 Maven 项目中。我已经向 pom.xml 添加了一个依赖项(在 http://mvnrepository.co
只是尝试在Android应用中发出一些POST请求。我正在用独立脚本中的HttpClient 4.5.3(https://hc.apache.org/downloads.cgi)测试。一切正常,但是当
我当前正在运行一个程序,该程序将使用 Apache HttpComponents 从网站下载源代码。我将下载很多(10,000 个),因此我使用多个线程来执行此操作。 有时所有线程都会死亡(加入),有
我最近从 java.net 切换过来至org.apache.http.client ,我设置了一个 ClosableHttpClient与 HttpClientBuilder 。作为连接管理器,我使用
我已经构建了一个 Storm 拓扑,它通过 kafka-spout 从 Apache-Kafka 接收元组,将此数据(使用另一个 Bolt)作为字符串写入本地系统上的 .txt 文件中,并从之后是我的
在 Android 上使用和选择发出 HTTP(S) 请求的方式是一个长期的痛苦。 虽然 Google 希望我们使用 HttpURLConnection,但有些人更喜欢使用 HttpClient。 有
我遇到了有关使用 apaches httpcomponents 进行基于证书的身份验证的问题。每次我启动请求时,我都会收到响应代码 403。如果我关闭 ssl 加密和身份验证,则可以成功建立连接。 我
根据 http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client
我正在编写一个 Java 程序,它使用 Apache-HttpComponents 加载页面并将其 HTML 打印到控制台;但是,该程序在抛出此错误之前仅打印了部分 HTML:每次我运行该程序时,在这
我想用 Apache http-components (4.1.2) 执行这个命令 curl --data "strings[]=testOne&string-keys[]=test.one&st
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
我想获取网站的 html,就像使用浏览器浏览一样。 当我尝试获取网站的 html 时,它与我使用 chrome 时的情况不同,我想知道是否可以使用 apache 的 HttpComponents 发出
我目前正在尝试让 HttpComponents 发送 HttpRequest 并检索响应。在大多数 URL 上,这都可以正常工作,但是当我尝试获取 phpBB 论坛的 URL 即 http://www
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我是一名优秀的程序员,十分优秀!