org.apache.http.client.methods.HttpPost#setProtocolVersion()源码实例Demo

下面列出了org.apache.http.client.methods.HttpPost#setProtocolVersion() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: vespa   文件: HttpServerConformanceTest.java
@Override
public Future<HttpResponse> executeRequest(
        final ClientProxy client,
        final boolean withRequestContent) throws Throwable {
    final HttpUriRequest request;
    final URI requestUri = URI.create("http://localhost:" + client.listenPort + "/status.html");
    if (!withRequestContent) {
        HttpGet httpGet = new HttpGet(requestUri);
        httpGet.setProtocolVersion(client.requestVersion);
        request = httpGet;
    } else {
        final HttpPost post = new HttpPost(requestUri);
        post.setEntity(new StringEntity(REQUEST_CONTENT, StandardCharsets.UTF_8));
        post.setProtocolVersion(client.requestVersion);
        request = post;
    }
    log.fine(() -> "executorService:"
            + " .isShutDown()=" + executorService.isShutdown()
            + " .isTerminated()=" + executorService.isTerminated());
    return executorService.submit(() -> client.delegate.execute(request));
}
 
源代码2 项目: xian   文件: ApacheHttpClient.java
@Override
public String post(String body) throws ConnectTimeoutException, SocketTimeoutException {
    /*
     * LOG.info(String.format(
     * "httpClient获取到的header: %s  ;   httpClient获取到的body:%s ", headers,
     * body));
     */
    if (client == null) {
        return INIT_FAIL;
    }
    HttpPost httpPost = new HttpPost(url);
    httpPost.setProtocolVersion(HttpVersion.HTTP_1_1);
    if (headers != null) {
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            httpPost.setHeader(entry.getKey(), entry.getValue());
        }
    }
    String responseContent;
    try {
        StringEntity entity = new StringEntity(body == null ? "" : body, "utf-8");
        entity.setContentEncoding("utf-8");
        entity.setContentType("application/json");
        httpPost.setEntity(entity);
        httpPost.setConfig(requestConfig);
        HttpResponse httpResponse = client.execute(httpPost);
        responseContent = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
    } catch (ConnectTimeoutException | SocketTimeoutException connectOrReadTimeout) {
        throw connectOrReadTimeout;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        httpPost.releaseConnection();
    }
    return responseContent;
}
 
源代码3 项目: red5-client   文件: RTMPTClientConnector.java
protected static HttpPost getPost(String uri) {
    HttpPost post = new HttpPost(uri);
    post.setProtocolVersion(HttpVersion.HTTP_1_1);
    return post;
}