apache-httpclient-4.x

set nonProxyHosts in Apache HttpClient 4.1.3

老子叫甜甜 提交于 2019-12-07 05:08:06
问题 I just cant help myself by answering this question. How can I set nonProxyHosts in the Apache HttpClient 4.1.3? In the old Httpclient 3.x that was quite simple. U could just set it using the setNonProxyHosts methods. But now, there's no equivalent method for the new version. I have been looking trough the api docs, tutorials and examples and havent found the solution so far. to set a normal proxy u can just do it by this: HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");

Header values overwritten on redirect in HTTPClient

风流意气都作罢 提交于 2019-12-06 18:16:30
I'm using httpclient 4.2.5 to make http requests which have to handle redirects as well. Here is a little example to understand the context: A sends http request (using httpclient 4.2.5) to B B sends 302 redirect (containing url to C) back to A A follows redirect to C C retrieves request URL and do some work with it If C parses the request URL by request.getRequestURL() (HttpServlet API) it contains e.g. host and port of the original request from step 1, which is wrong. The problem exists in step 2, where httpclient handles the redirect. It just copies all headers from the original request

Migrating from HttpClient 3.x to 4.x

被刻印的时光 ゝ 提交于 2019-12-06 16:49:40
问题 We have some code written using commons-httpclient-3.1 that needs to be converted to 4.1. I'm only somewhat familiar with this and am reading the 4.1 httpclient tutorial now. I see a couple of posts here (e.g. Converting from HttpClient 3 to 4 but that's about a specific construct). Seems like there should be some docs/examples somewhere showing how to upgrade usage of 3.x to 4.x ? One specific example: replacing use of org.apache.commons.httpclient.HttpState 回答1: I would replace the library

Apache HttpClient use own SSL-certificates

允我心安 提交于 2019-12-06 15:04:41
问题 I am trying to connect to a https secured restwebservice using httpclient 4.0.3 with Java7. My code looks like this: public static void main(String[] args) throws Exception { ClientRequest req = new ClientRequest("https://127.0.0.16:8443/rest/lstgs/create", new ApacheHttpClient4Executor(doSSLBlackMagic())); // ... random stuff that has nothing to do with SSL ClientResponse<String> response = req.post(String.class); if (response.getStatus() != 201) { throw new RuntimeException("error, status:

How to set redirect strategy in apache async http client

老子叫甜甜 提交于 2019-12-06 13:31:26
How i can set redirect strategy in apache async http client? I have something like this (scala code). Commented code works as expected, but i am not able to perform more than 4 concurrent request to one host per second, second version can handle much more concurrent connections but doesn't handle redirects at all. object HttpClientManager { def createHttpClient(): CloseableHttpAsyncClient = { //cm: NHttpClientConnectionManager /* val httpClient = HttpAsyncClients .custom() .setDefaultRequestConfig(config) //.setConnectionManager(cm) .build() */ // val config = RequestConfig.custom() //

Peer not authenticated in java

一笑奈何 提交于 2019-12-06 12:54:17
问题 I have gone to almost all the post related to this exception. Actually my problem is I have an java application through which I am hitting an URL and getting response from it. code to hit URL is : HttpGet getRequest = new HttpGet("https://urlto.esb.com"); HttpResponse httpResponse = null; DefaultHttpClient httpClient = new DefaultHttpClient(); httpResponse = httpClient.execute(getRequest); Here I am getting javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated So after some Google

HTTP/1.1 401 Authorization Required with HttpClient 4.1.1

廉价感情. 提交于 2019-12-06 12:34:29
问题 Updated Code:- Using SSL, still am getting the same error.. I am trying to open this uri https://some-host/a/getmeta?id=10 (this url is passed to proxi.jsp page) And this is my proxi.jsp page, And I am getting this error HTTP/1.1 401 Authorization Required and when I am passing my credentials too. Why is it happening so.. And that site use siteminder. <%@ page language="java" import=" org.apache.http.HttpEntity, org.apache.http.HttpResponse, org.apache.http.auth.AuthScope, org.apache.http

How to configure the number of allowed pending requests in Apache async client

耗尽温柔 提交于 2019-12-06 09:37:09
I'm developing an HTTP client application, using Apache httpasyncclient version 4.0.2. I would like to configure the maximum number of pending requests. Initially I assumed this number is the same as the maximum number of connections. I set this to 20 in the following way: final CloseableHttpAsyncClient httpclient; In the constructor: final NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory = new ManagedNHttpClientConnectionFactory(new DefaultHttpRequestWriterFactory(), new DefaultHttpResponseParserFactory(), HeapByteBufferAllocator.INSTANCE); final IOReactorConfig

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated issue

南笙酒味 提交于 2019-12-06 09:24:52
问题 I am using HttpClient-4.2.1 and already added certificate on server but still I am getting below error. I have read existing issue saying to add TrustManager ( X509TrustManager ) but as per my thinking this is not solution. If I am wrong please correct me. javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397) at org.apache.http.conn.ssl

java char encoding for strange string from API

偶尔善良 提交于 2019-12-06 08:59:08
I'm having strange issue with a response got from API. I'm using apache HTTP Client to get response. Response header has the following Content-Type=[application/json; charset=utf-16] Transfer-Encoding=[chunked] X-Powered-By=[ASP.NET] // Yes, people using ASP.NET So based on this, when I get response, my response looks like follows 笀∀匀琀愀琀甀猀䌀漀搀攀∀㨀㈀  So I tried the following. String body = "笀∀匀琀愀琀甀猀䌀漀搀攀∀㨀㈀"; String charSetString = "utf-8|utf-16|utf-16le, all possible combination" body = new String(body.getBytes(Charset.forName(charSetString)); body = body.replaceAll("[^\\x00-\\x7F]", ""); But no