2014-09-08 2 views
0

Я хочу добавить org.apache.http в свой проект, и я скачал и добавил его в свой проект, я разработал некоторые коды для тестирования, но когда я удаляю org.apache.http из моего проекта, мои коды отлично работают, добавляется org.apache.http по умолчанию в Android SDK и нет необходимости добавлять его в проект?Android: apache HttpComponents Core

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(); 
     } 
    } 
} 

ответ

0

Да, org.apache.http является частью API для Android.

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

Но это, кажется, вилка устаревшей версии Apache HTTPClient:
https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

+0

Это добавило в SDK 20? – 2014-09-09 05:48:38

+0

Нет, кажется, что он был там с первого же начала. Справочный API указывает «Добавлен в уровень API 1» –

Смежные вопросы