首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android : apache HttpComponents核心

Android : apache HttpComponents核心
EN

Stack Overflow用户
提问于 2014-09-08 06:40:53
回答 1查看 198关注 0票数 0

我想将org.apache.http添加到我的项目中,我下载并将它添加到我的项目中,我开发了一些用于测试的代码,但是当我从项目中删除org.apache.http时,我的代码运行良好,在android中默认添加了org.apache.http,并且没有必要将它添加到项目中?

代码语言:javascript
复制
public class ElementalHttpGet {

    public static void main(String[] args) throws Exception {
        HttpProcessor httpproc = HttpProcessorBuilder.create()
            .add(new RequestContent())
            .add(new RequestTargetHost())
            .add(new RequestConnControl())
            .add(new RequestUserAgent("Test/1.1"))
            .add(new RequestExpectContinue(true)).build();

        HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

        HttpCoreContext coreContext = HttpCoreContext.create();
        HttpHost host = new HttpHost("localhost", 8080);
        coreContext.setTargetHost(host);

        DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
        ConnectionReuseStrategy connStrategy = DefaultConnectionReuseStrategy.INSTANCE;

        try {
            String[] targets = {
                "/",
                "/servlets-examples/servlet/RequestInfoExample",
                "/somewhere%20in%20pampa"};

            for (int i = 0; i < targets.length; i++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket);
                }
                BasicHttpRequest request = new BasicHttpRequest("GET", targets[i]);
                System.out.println(">> Request URI: " + request.getRequestLine().getUri());

                httpexecutor.preProcess(request, httpproc, coreContext);
                HttpResponse response = httpexecutor.execute(request, conn, coreContext);
                httpexecutor.postProcess(response, httpproc, coreContext);

                System.out.println("<< Response: " + response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
                System.out.println("==============");
                if (!connStrategy.keepAlive(response, coreContext)) {
                    conn.close();
                } else {
                    System.out.println("Connection kept alive...");
                }
            }
        } finally {
            conn.close();
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-08 08:40:33

是的,org.apache.http是Android的一部分。

http://developer.android.com/reference/org/apache/http/package-summary.html

但这似乎是Apache HttpClient过时的versión的一个分支:

https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25718658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档