apache-httpclient-4.x

How to prevent hangs on SocketInputStream.socketRead0 in Java?

亡梦爱人 提交于 2019-12-17 17:25:06
问题 Performing millions of HTTP requests with different Java libraries gives me threads hanged on: java.net.SocketInputStream.socketRead0() Which is native function. I tried to set up Apche Http Client and RequestConfig to have timeouts on (I hope) everythig that is possible but still, I have (probably infinite) hangs on socketRead0 . How to get rid of them? Hung ratio is about ~1 per 10000 requests (to 10000 different hosts) and it can last probably forever (I've confirmed thread hung as still

JsonparseException Illegal unquoted character ((CTRL-CHAR, code 10)

╄→尐↘猪︶ㄣ 提交于 2019-12-17 15:43:32
问题 I'm trying to use org.apache.httpcomponents to consume a rest api ,which will post json format data to api. while I get exception Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string. The reason is ctrl-char is included in the json string. Is there any way to replace this .or some solution else? thanks! 回答1: This can happen if you have a newline (or other control character) in a

Android: IllegalStateException in HttpGet

橙三吉。 提交于 2019-12-17 10:04:20
问题 I'm trying to send a GET request using HttpClient , but I keep getting an IllegalStateException . Any idea what's causing this? I've been looking around for a solution, but I don't get what it means by "host=null" in the log. How do I set the host, and how is it different from the path? Here's my logcat out: 07-17 11:54:18.002: W/System.err(15422): java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=google.com 07-17 11:54:18.002: W

Does Apache Commons HttpClient support GZIP?

こ雲淡風輕ζ 提交于 2019-12-17 09:38:18
问题 Does the library Apache Commons HttpClient support Gzip? We wanted to use enable gzip compression on our Apache server to speed up the client/server communications (we have a php page that allows our Android application to sync files with the Server). 回答1: Apache HttpClient 4.1 supports content compression out of the box along with many other features that were previously considered out of scope. 回答2: If your server is able to provide GZIPped content, with Apache Http client 4.1 all you need

javax.net.ssl.SSLPeerUnverifiedException: Host name does not match the certificate subject provided by the peer

天大地大妈咪最大 提交于 2019-12-17 09:14:26
问题 I follow many links on stackoverflow and tried many solutions, but none of them worked for me. I'm using WSO2 API manager version 1.9.1 . I am facing following error: Exception in thread "main" javax.net.ssl.SSLPeerUnverifiedException: Host name 'XXXXXXXXX' does not match the certificate subject provided by the peer (CN=localhost, O=WSO2, L=Mountain View, ST=CA, C=US) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:465) at org.apache.http

Apache HttpClient timeout

耗尽温柔 提交于 2019-12-17 08:29:27
问题 Is there a way to specify a timeout for the whole execution of HttpClient? I have tried the following: httpClient.getParams().setParameter("http.socket.timeout", timeout * 1000); httpClient.getParams().setParameter("http.connection.timeout", timeout * 1000); httpClient.getParams().setParameter("http.connection-manager.timeout", new Long(timeout * 1000)); httpClient.getParams().setParameter("http.protocol.head-body-timeout", timeout * 1000); It actually works fine, except if a remote host

How to set TLS version on apache HttpClient

南楼画角 提交于 2019-12-17 04:54:33
问题 How can I change the supported TLS versions on my HttpClient? I'm doing: SSLContext sslContext = SSLContext.getInstance("TLSv1.1"); sslContext.init( keymanagers.toArray(new KeyManager[keymanagers.size()]), null, null); SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, new String[]{"TLSv1.1"}, null, null); Scheme scheme = new Scheme("https", 443, socketFactory); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(scheme); BasicClientConnectionManager

Apache HttpClient 4.0.3 - how do I set cookie with sessionID for POST request?

老子叫甜甜 提交于 2019-12-17 04:22:52
问题 can you tell me how to store jsessionid in cookie, so it can be passed to the servlet with post request? I'm using Apache HttpClient version 4.0.3. All the solutions I've found explains how to do this with HttpClient 3.1. I've read tutorial and tried this, but it isn't working. HttpPost httppost = new HttpPost(postData); CookieStore cookieStore = new BasicCookieStore(); BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", getSessionId()); cookieStore.addCookie(cookie); client

Deprecated Java HttpClient - How hard can it be?

与世无争的帅哥 提交于 2019-12-17 03:26:34
问题 All I'm trying to do is download some JSON and deserialize it into an object. I haven't got as far as downloading the JSON yet. Almost every single HttpClient example I can find, including those on the apache site looks something like... import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; public void blah() { HttpClient client = new DefaultHttpClient(); ... } However, Netbeans tells me that DefaultHttpClient is deprecated. I've tried googling for

Deprecated Java HttpClient - How hard can it be?

会有一股神秘感。 提交于 2019-12-17 03:26:18
问题 All I'm trying to do is download some JSON and deserialize it into an object. I haven't got as far as downloading the JSON yet. Almost every single HttpClient example I can find, including those on the apache site looks something like... import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; public void blah() { HttpClient client = new DefaultHttpClient(); ... } However, Netbeans tells me that DefaultHttpClient is deprecated. I've tried googling for