apache-httpclient-4.x

What is the difference between CloseableHttpClient and HttpClient in Apache HttpClient API?

江枫思渺然 提交于 2019-11-28 03:18:45
I'm studying an application developed by our company. It uses the Apache HttpClient library. In the source code it uses the HttpClient class to create instances to connect to a server. I want to learn about Apache HttpClient and I've gone trough this set of examples . All the examples use CloseableHttpClient instead of HttpClient . So I think CloseableHttpClient is an extended version of HttpClient . If this is the case I have two questions: What is the difference between these two? Which class is recommended to use for my new development? The main entry point of the HttpClient API is the

How to prevent hangs on SocketInputStream.socketRead0 in Java?

社会主义新天地 提交于 2019-11-28 03:15:25
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 valid after 10 hours). JDK 1.8 on Windows 7. My HttpClient factory: SocketConfig socketConfig =

Apache HttpClient 4.1 on Android

血红的双手。 提交于 2019-11-28 00:16:52
Has anyone tried to use a newer version of Apache HttpClient on Android? There's an annoying bug in the HttpClient used by Android and I was wondering if I would run into problems trying to redistribute HttpClient 4.1 with my app. I created a script to convert a stock HttpClient release into an Android library project. The packages are renamed so that there's no confusion of which classes are used. Also ThreadSafeClientConnManager and Scheme work just fine. Take a look: httpclientandroidlib That doesn't looks as good idea, especially if package and class names were not changed in newer version

Apache HttpClient GET with body

假如想象 提交于 2019-11-27 22:07:47
I am trying to send an HTTP GET with a json object in its body. Is there a way to set the body of an HttpClient HttpGet? I am looking for the equivalent of HttpPost#setEntity. torbinsky From what I know, you can't do this with the default HttpGet class that comes with the Apache library. However, you can subclass the HttpEntityEnclosingRequestBase entity and set the method to GET. I haven't tested this, but I think the following example might be what you're looking for: import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; public class HttpGetWithEntity extends

Tomcat 7 getting SSLv2Hello is disabled error when trying to make client server ssl authntication

不问归期 提交于 2019-11-27 21:24:18
问题 I have tried to setup a self-signed TLS configuration for both client and server where the server is Tomcat 7 and the client is Apache httpclient 4.1. The server configuration is taken from this here and the client code is taken from here. My tomcat configuration looks like this: <Connector clientAuth="true" port="8443" minSpareThreads="5" maxSpareThreads="75" enableLookups="true" disableUploadTimeout="true" acceptCount="100" maxThreads="200" scheme="https" secure="true" SSLEnabled="true"

How do I use an SSL client certificate with Apache HttpClient?

烈酒焚心 提交于 2019-11-27 20:34:42
In Python I was using requests like this: requests.put( webdavURL, auth=(tUsername, tPassword), data=webdavFpb, verify=False, cert=("/path/to/file.pem", "/path/to/file.key")) Easy as pie. Now I need to implement the same thing in Java using Apache HttpClient. How can I pass a client certificate when making requests using HttpClient? I think the main difference is that in java, you usually put the key and the certificate to a key store and use it from there. Like you mention often people do want to use a separate library for it, like mentioned httpcomponents client (just like you're using

Java http clients and POODLE

你说的曾经没有我的故事 提交于 2019-11-27 20:12:08
Regarding the POODLE vulnerability, if I understand it correctly, it requires a client that automatically downgrades TLS protocol to SSLv3 when failing to establish a secure channel with a server using higher version protocol advertised by the server. Do the common java HTTP client libraries, specifically javax.net.ssl.HttpsURLConnection and Apache HttpClient, automatically downgrade the TLS protocol when failing to establish TLS session with a server? If not, am I correct that they are immune from he POODLE attack unless either (a) the server only supports SSLv3, or (b) a logic at a higher

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

*爱你&永不变心* 提交于 2019-11-27 19:34:09
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! This can happen if you have a newline (or other control character) in a JSON string literal. {"foo": "bar baz"} If you are the one producing the data, replace actual newlines with

commons httpclient - Adding query string parameters to GET/POST request

痞子三分冷 提交于 2019-11-27 18:55:15
I am using commons HttpClient to make an http call to a Spring servlet. I need to add a few parameters in the query string. So I do the following: HttpRequestBase request = new HttpGet(url); HttpParams params = new BasicHttpParams(); params.setParameter("key1", "value1"); params.setParameter("key2", "value2"); params.setParameter("key3", "value3"); request.setParams(params); HttpClient httpClient = new DefaultHttpClient(); httpClient.execute(request); However when i try to read the parameter in the servlet using ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())

Java HtmlUnit - can't login to wordpress

て烟熏妆下的殇ゞ 提交于 2019-11-27 18:34:58
问题 I'm trying to use HtmlUnit to login to my local wordpress website but it seems to have a cookies issue. That's that begining of the code: WebClient webClient = new WebClient(); HtmlPage loginPage = webClient.getPage("http://localhost/flowersWp/wp-admin"); HtmlForm form = loginPage.getFormByName("loginform"); That's what I get in the log. Anyone has an idea? Thanks. Nov 27, 2010 12:43:35 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Cookie rejected: "