cz.msebera.android.httpclient.client.HttpClient.execute()方法的使用及代码示例

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

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

HttpClient.execute介绍

[英]Executes HTTP request using the default context.
[中]使用默认上下文执行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: 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

@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;
    }
  }
}

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

try {
  metrics.getScheduledConnections().decrementAndGet();
  final V result = httpclient.execute(request, responseHandler, context);
  ended = System.currentTimeMillis();
  metrics.getSuccessfulConnections().increment(started);

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

@Override
public void httpApachePostRequest(HttpPost post, HttpReadResult result) throws ConnectionException {
  try {
    // TODO: Redo like for get request
    if (result.authenticate) {
      signRequest(post);
    }
    result.strResponse = ApacheHttpClientUtils.getHttpClient(data.getSslMode()).execute(
        post, new BasicResponseHandler());
  } catch (Exception e) {
    // We don't catch other exceptions because in fact it's vary difficult to tell
    // what was a real cause of it. So let's make code clearer.
    result.setException(e);
  }
}

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

@Override
public void httpApachePostRequest(HttpPost postMethod, HttpReadResult result) throws ConnectionException {
  try {
    HttpClient client = ApacheHttpClientUtils.getHttpClient(data.getSslMode());
    postMethod.setHeader("User-Agent", HttpConnection.USER_AGENT);
    if (getCredentialsPresent()) {
      postMethod.addHeader("Authorization", "Basic " + getCredentials());
    }
    HttpResponse httpResponse = client.execute(postMethod);
    StatusLine statusLine = httpResponse.getStatusLine();
    result.statusLine = statusLine.toString();
    result.setStatusCode(statusLine.getStatusCode());
    result.strResponse = ApacheHttpClientUtils.readHttpResponseToString(httpResponse);
  } catch (Exception e) {
    result.setException(e);
  } finally {
    postMethod.abort();
  }
}

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

final HttpResponse response = backend.execute(target, wrapped, localContext);
try {
  contentEncodingInterceptor.process(response, localContext);

相关文章