apache-httpclient-4.x

HttpClient fails with Handshake Failed in Android 5.0 Lollipop

陌路散爱 提交于 2019-11-30 03:36:05
DefaultHttpClient in Android 5.0 Lollipop seems to be broken. It can not set the connection to some sites that were successfully set by previous versions of Android. For example I try to connect to https://uralsg.megafon.ru //Create httpclient like in https://stackoverflow.com/questions/18523784/ssl-tls-protocols-and-cipher-suites-with-the-androidhttpclient HttpClient client = new DefaultHttpClient(manager, params); HttpGet httpGet = new HttpGet("https://uralsg.megafon.ru"); HttpResponse client = httpclient.execute(httpGet); This code works in Android 2.3-4.4, but fails on Android 5.0 (devices

How to add,set and get Header in request of HttpClient?

两盒软妹~` 提交于 2019-11-30 03:30:22
In my application I need to set the header in the request and I need to print the header value in the console... So please give an example to do this the HttpClient or edit this in my code... My Code is , import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl

Java HttpRequest JSON & Response Handling

感情迁移 提交于 2019-11-30 02:33:12
I have looked at several other questions, but I still don't fully understand this. I want to POST a JSON string to a remote address and then retrieve the values from the JSON response. I am using the Apache libraries for Java. public HttpResponse http(String url, String body) throws IOException { try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { HttpPost request = new HttpPost(url); StringEntity params = new StringEntity(body); request.addHeader("content-type", "application/json"); request.setEntity(params); //httpClient.execute(request); HttpResponse result =

fix java.net.SocketTimeoutException: Read timed out

耗尽温柔 提交于 2019-11-30 01:59:33
I have a RESTful server which takes an http POST input from client to vote up songs on server. I have used Apache HTTPClient for client. public boolean vote() { HttpClient client = new DefaultHttpClient(getHttpParameters()); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout Limit HttpResponse response; try { HttpPost post = new HttpPost("http://127.0.0.1:8080/ws/"); StringEntity se = new StringEntity("{ \"song_id\" : \"2\" }"); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,"application/json")); post.setEntity(se); response = client.execute(post); if

Invalid use of BasicClientConnManager: connection still allocated

a 夏天 提交于 2019-11-29 22:51:36
I am making a call to REST URL and trying to measure how much time it is taking to get the response back. I am using DefaultHttpClient for that to get the response back from REST URL . In my below program , each thread will be working on a particular range. Like Each Thread will work between 1 - 100 and second thread will work between 101 - 200 etc. SO in my below code, for the first time it works fine. But for the second time, it is throwing exception on this line httpclient.execute for the second time as- java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection

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

∥☆過路亽.° 提交于 2019-11-29 22:49:17
public HttpClientVM() { BasicHttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 10); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params, false); HttpConnectionParams.setStaleCheckingEnabled(params, true); HttpConnectionParams.setConnectionTimeout(params, 30000); HostnameVerifier hostnameVerifier= org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory()

Conflict between httpclient version and Apache Spark

白昼怎懂夜的黑 提交于 2019-11-29 21:05:14
问题 I'm developing a Java application using Apache Spark. I use this version: <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_2.10</artifactId> <version>1.2.2</version> </dependency> In my code, there is a transitional dependency: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </dependency> I package my application into a single JAR file. When deploying it on EC2 instance using spark-submit , I get

Apache HttpComponents HttpClient timeout

风格不统一 提交于 2019-11-29 20:16:43
How do I set the connection timeout in httpcomponents httpclient? I have found the documentation at: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html but it is not clear how these parameters are actually set. Also, an explanation of the difference between SO_TIMEOUT and CONNECTION_TIMEOUT would be helpful. 30thh In version 4.3 of Apache Http Client the configuration was refactored (again). The new way looks like this: RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder.setConnectTimeout(timeout); requestBuilder.setConnectionRequestTimeout

Android API 23 - HttpClient 4.X repackaged

拈花ヽ惹草 提交于 2019-11-29 19:33:41
问题 Disclaimer I know we shouldn't use HttpClient on Android anymore In API 23 we have option to use useLibrary 'org.apache.http.legacy' I'd like to continue using HttpClient (also I maintain libraries and projects based on it) however, with API 23 the classes are gone. Well not gone with useLibrary workaround, but cannot be used to develop any further (classes don't autocomplete, everything is shown as invalid code) We also have option to use HttpComponents provided Android fork of HttpClient 4

How do Jersey-client and Apache HTTP Client compare?

馋奶兔 提交于 2019-11-29 19:31:51
First of all, I'm not trying to start a flame-war here. I know Jersey sufficiently well, but have hardly used httpclient. What are the key differences between jersey-client and Apache's httpclient? In what areas is one better than the other? Is there a good comparison chart somewhere? Which one performs better with larger files (say 2048 MB)? Many thanks for your comments! These two things probably should not be compared directly. Jersey is a REST-client, featuring full JAX-RS implementation, neat fluent API and a powerfull filter stack. Apache Http Client is a HTTP-client, perfect in managing