Java Code Examples for org.apache.http.client.methods.HttpPost#setProtocolVersion()
The following examples show how to use
org.apache.http.client.methods.HttpPost#setProtocolVersion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServerConformanceTest.java From vespa with Apache License 2.0 | 6 votes |
@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)); }
Example 2
Source File: ApacheHttpClient.java From xian with Apache License 2.0 | 5 votes |
@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; }
Example 3
Source File: RTMPTClientConnector.java From red5-client with Apache License 2.0 | 4 votes |
protected static HttpPost getPost(String uri) { HttpPost post = new HttpPost(uri); post.setProtocolVersion(HttpVersion.HTTP_1_1); return post; }