apache-httpcomponents

Hashicorp Vault - Unrecognized SSL message, plaintext connection? [duplicate]

为君一笑 提交于 2021-01-28 19:44:03
问题 This question already has answers here : Unrecognized SSL message, plaintext connection? Exception (19 answers) Closed 4 years ago . I am trying to setup a java application to connect to Hashicorp's vault and authenticate using the TLS backend (using an SSL Certificate) I am using apache httpcomponents 4.4 as follows: final CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(mySslContext).build(); final CloseableHttpResponse response = httpclient.execute(myRequest) where

Monitor connection pool of PoolingHttpClientConnectionManager

余生长醉 提交于 2021-01-21 10:32:13
问题 I'd like to monitor the connection pool of a Apache httpComponents PoolingHttpClientConnectionManager but cannot find a way to access it. We create our HttpClient using the following builder: HttpClient httpClient = HttpClientBuilder.create() .setMaxConnTotal(maxConnections) .setMaxConnPerRoute(maxConnectionsPerRoute) .build(); This creates an instance of an InternalHttpClient , which holds an instance of a PoolingHttpClientConnectionManager , which holds an instance of a CPool . CPool would

How does HttpAsyncClient 4 work?

纵然是瞬间 提交于 2020-08-24 06:58:11
问题 In previous versions of HttpClient target host was set up into client itself. In last version (for HttpAsyncClient it's 4.1.1) host is set up into HttpRequest ( HttpGet , HttpPost etc.) every time I do a request. I want to use persistent connection, so I use HttpAsyncClient . I create and use it like this: CloseableHttpAsyncClient client = HttpAsyncClients.createDefault(); client.start(); List<Future<HttpResponse>> responses = new ArrayList<>(); for (int i = 0; i < 10; i++) { HttpGet get =

How does HttpAsyncClient 4 work?

我的未来我决定 提交于 2020-08-24 06:57:59
问题 In previous versions of HttpClient target host was set up into client itself. In last version (for HttpAsyncClient it's 4.1.1) host is set up into HttpRequest ( HttpGet , HttpPost etc.) every time I do a request. I want to use persistent connection, so I use HttpAsyncClient . I create and use it like this: CloseableHttpAsyncClient client = HttpAsyncClients.createDefault(); client.start(); List<Future<HttpResponse>> responses = new ArrayList<>(); for (int i = 0; i < 10; i++) { HttpGet get =

Apache HttpClient response content length returns -1

无人久伴 提交于 2020-05-29 03:49:33
问题 Why does the following Code returns -1? Seems that the request failed. public static void main(String[] args) { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet("http://www.google.de"); HttpResponse response; try { response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); // Prints -1 System.out.println(entity.getContentLength()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch

MultipartEntityBuilder: Omit Content-Type and Content-Transfer

你说的曾经没有我的故事 提交于 2020-05-13 02:40:29
问题 I'm trying to mimic my Browsers behaviour on a multipart/form-data POST request using org.apache.http.entity.mime.MultipartEntityBuilder My browser only sends Content-Disposition, but no Content-Type or Content-Transfer-Encoding Headers. I tried to use MultipartEntityBuilder.addPart() and addTextBody() but both add those Headers by default: What I want (what my chrome browser does): POST .../some.jsp HTTP/1.1 Host: ... Connection: keep-alive Content-Type: multipart/form-data; boundary=---

How to set SNI (Server Name Indication) in TLS Handshake using Apache HttpComponents Java

时光毁灭记忆、已成空白 提交于 2020-01-25 06:53:48
问题 I'm using org.apache.http.ssl.SSLContextBuilder to provide my certificate/keys in my HTTPS requests, but I would like to customize my SNI in TLS Handshake and I'm not sure where I can do this Does Apache Java Lib allow this customization? I found https://hc.apache.org/httpcomponents-client-4.5.x/httpclient/apidocs/org/apache/http/conn/ssl/SSLConnectionSocketFactory.html and How to enable SNI in HTTP request using Apache HTTPComponents HttpClient? but both does not have anything about methods

What is wrong with this POST request implementation?

杀马特。学长 韩版系。学妹 提交于 2020-01-23 04:35:07
问题 I have been working around Google OAuth 2.0 with java and got struck with some unknown error during implementation. The following CURL for POST request works fine: curl -v -k --header "Content-Type: application/x-www-form-urlencoded" --data "code=4%2FnKVGy9V3LfVJF7gRwkuhS3jbte-5.Arzr67Ksf-cSgrKXntQAax0iz1cDegI&client_id=[my_client_id]&client_secret=[my_client_secret]&redirect_uri=[my_redirect_uri]&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token And produces the

Response size limit when using Apache HttpComponents

只愿长相守 提交于 2020-01-05 07:35:09
问题 I am converting some code from the Http Client 3.x library over to the Http Components 4.x library. The old code contains a check to make sure that the response is not over a certain size. This is fairly easy to do in Http Client 3.x since you can get back a stream from the response using the getResponseBodyAsStream() method and determine when the size has been exceeded. I can't find a similar way in Http Components. Here's the old code as an example of what I'm trying to do: private static

Android ClassNotFoundException for HttpComponents

我们两清 提交于 2020-01-05 07:03:51
问题 I am in a weird situation, which I have no idea what's going on. The code was working, until I upgraded my Android SDK to r17. The code is able to compile, but during runtime, Eclipse throws ClassNotFoundException() , under findClass method, in PathClassLoader.class The class that not found are "org.apache.http.entity.mime.content.ContentBody" and "org.apache.http.entity.mime.content.StringBody" I already imported in the latest (4.1.3) http components jar file into project-> properties-> java