cz.msebera.android.httpclient.client.HttpClient类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(538)

本文整理了Java中cz.msebera.android.httpclient.client.HttpClient类的一些代码示例,展示了HttpClient类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient类的具体详情如下:
包路径:cz.msebera.android.httpclient.client.HttpClient
类名称:HttpClient

HttpClient介绍

[英]This interface represents only the most basic contract for HTTP request execution. It imposes no restrictions or particular details on the request execution process and leaves the specifics of state management, authentication and redirect handling up to individual implementations.
[中]此接口仅表示HTTP请求执行的最基本契约。它没有对请求执行过程施加任何限制或特定细节,并将状态管理、身份验证和重定向处理的细节留给各个实现。

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void run() {
  try {
   HttpGet get=new HttpGet(SO_URL);
   String json=client.execute(get, new BasicResponseHandler());
   final SOQuestions result=
    new Gson().fromJson(new StringReader(json),
     SOQuestions.class);
   runOnUiThread(new Runnable() {
    @Override
    public void run() {
     setListAdapter(new ItemsAdapter(result.items));
    }
   });
  }
  catch (IOException e) {
   onConnectionException(e);
  }
 }
}.start();

代码示例来源:origin: cz.msebera.android/httpclient

public HttpParams getParams() {
  return backend.getParams();
}

代码示例来源:origin: cz.msebera.android/httpclient

public ClientConnectionManager getConnectionManager() {
  return backend.getConnectionManager();
}

代码示例来源:origin: cz.msebera.android/httpclient

public HttpParams getParams() {
  return backend.getParams();
}

代码示例来源:origin: cz.msebera.android/httpclient

public ClientConnectionManager getConnectionManager() {
  return backend.getConnectionManager();
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void run() {
  try {
   HttpClient client=HttpClientBuilder.create()
    .setConnectionManager(
     new PoolingHttpClientConnectionManager())
    .build();
   HttpGet get=new HttpGet(SO_URL);

   try {
    String result=client.execute(get, new BasicResponseHandler());
    SOQuestions questions=
      new Gson().fromJson(result, SOQuestions.class);

    EventBus.getDefault().post(new QuestionsLoadedEvent(questions));
   }
   catch (IOException e) {
    Log.e(getClass().getSimpleName(), "Exception parsing JSON", e);
   }
  }
  catch (Exception e) {
   Log.e(getClass().getSimpleName(), "Exception parsing JSON", e);
  }
 }
}

代码示例来源:origin: andstatus/andstatus

static HttpClient getHttpClient() {
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  
  SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
  // This is done to get rid of the "javax.net.ssl.SSLException: hostname in certificate didn't match" error
  // See e.g. http://stackoverflow.com/questions/8839541/hostname-in-certificate-didnt-match
  socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);        
  schemeRegistry.register(new Scheme("https", socketFactory, 443));
  HttpParams params = getHttpParams();        
  ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
  HttpClient client = new DefaultHttpClient(clientConnectionManager, params);
  client.getParams()
      .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
          MyPreferences.getConnectionTimeoutMs())
      .setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
          MyPreferences.getConnectionTimeoutMs());
  return client;
}

代码示例来源:origin: andstatus/andstatus

@Override
protected oauth.signpost.http.HttpResponse sendRequest(HttpRequest request) throws Exception {
  HttpResponse response = httpClient.execute((HttpUriRequest) request.unwrap());
  return new HttpResponseAdapter(response);
}

代码示例来源:origin: andstatus/andstatus

@Override
public HttpResponse httpApacheGetResponse(HttpGet httpGet) throws IOException {
  HttpClient client = ApacheHttpClientUtils.getHttpClient(data.getSslMode());
  return client.execute(httpGet);
}

代码示例来源:origin: andstatus/andstatus

@Override
public HttpResponse httpApacheGetResponse(HttpGet httpGet) throws IOException {
  return ApacheHttpClientUtils.getHttpClient(data.getSslMode()).execute(httpGet);
}

代码示例来源:origin: guardianproject/NetCipher

@Override
  public void run() {
    try {
      HttpGet get = new HttpGet(SO_URL);
      String json = client.execute(get, new BasicResponseHandler());
      final SOQuestions result =
          new Gson().fromJson(new StringReader(json),
              SOQuestions.class);
      runOnUiThread(new Runnable() {
        @Override
        public void run() {
          setListAdapter(new ItemsAdapter(result.items));
        }
      });
    } catch (IOException e) {
      onConnectionException(e);
    }
  }
}.start();

代码示例来源:origin: guardianproject/NetCipher

@Override
  public void run() {
    try {
      HttpGet get = new HttpGet(StrongBuilderBase.TOR_CHECK_URL);
      String result = connection.execute(get, new BasicResponseHandler());
      JSONObject json = new JSONObject(result);
      if (json.optBoolean("IsTor", false)) {
        callback.onConnected(connection);
      } else {
        callback.onInvalid();
      }
    } catch (Exception e) {
      callback.onConnectionException(e);
    }
  }
}.start();

代码示例来源:origin: harjot-oberai/AndroidDigitClassifier

HttpResponse getResponse = null;
try {
  getResponse = httpclient.execute(get);
} catch (ClientProtocolException e) {

代码示例来源:origin: codepath/intro_android_demo

protected String loadUrlBody(String address) {
  HttpClient httpclient = new DefaultHttpClient();
  HttpResponse response = null;
  String responseString = null;
  try {
    response = httpclient.execute(new HttpGet(address));
    StatusLine statusLine = response.getStatusLine();
    if(statusLine.getStatusCode() == HttpStatus.SC_OK){
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      response.getEntity().writeTo(out);
      out.close();
      responseString = out.toString();
    } else{
      response.getEntity().getContent().close();
      throw new IOException(statusLine.getReasonPhrase());
    }
  } catch (ClientProtocolException e) {
  } catch (IOException e) {
  }
  
  return responseString;
}

代码示例来源:origin: harjot-oberai/AndroidDigitClassifier

HttpResponse response = httpclient.execute(httppost);

代码示例来源:origin: guardianproject/NetCipher

@Override
 protected void loadResult(HttpClient client)
  throws Exception {
  HttpGet get=new HttpGet(TEST_URL);
  testResult=client.execute(get, new BasicResponseHandler());
 }
});

代码示例来源:origin: guardianproject/NetCipher

@Override
 protected void loadResult(HttpClient client)
  throws Exception {
  HttpGet get=new HttpGet(TEST_URL);
  testResult=client.execute(get, new BasicResponseHandler());
 }
});

代码示例来源:origin: rajeeviiit/AndroidProject

HttpResponse response = httpclient.execute(post);

代码示例来源:origin: rajeeviiit/AndroidProject

HttpResponse response = httpclient.execute(post);

代码示例来源:origin: cz.msebera.android/httpclient

public HttpResponse execute(final HttpHost target, final HttpRequest request,
    final HttpContext context) throws IOException {
  for (int c = 1;; c++) {
    final HttpResponse response = backend.execute(target, request, context);
    try {
      if (retryStrategy.retryRequest(response, c, context)) {
        EntityUtils.consume(response.getEntity());
        final long nextInterval = retryStrategy.getRetryInterval();
        try {
          log.trace("Wait for " + nextInterval);
          Thread.sleep(nextInterval);
        } catch (final InterruptedException e) {
          Thread.currentThread().interrupt();
          throw new InterruptedIOException();
        }
      } else {
        return response;
      }
    } catch (final RuntimeException ex) {
      try {
        EntityUtils.consume(response.getEntity());
      } catch (final IOException ioex) {
        log.warn("I/O error consuming response content", ioex);
      }
      throw ex;
    }
  }
}

相关文章