Questions tagged [apache-httpclient-4.x]

A Java HTTP client library. Supersedes the Commons HttpClient project.

See http://hc.apache.org/httpcomponents-client-ga/index.html

For questions related to the Apache Commons HttpClient v3.x (or older), see

For questions related to the general Apache HttpComponents project, see

2333 questions
430
votes
22 answers

Trusting all certificates using HttpClient over HTTPS

Recently posted a question regarding the HttpClient over Https (found here). I've made some headway, but I've run into new issues. As with my last problem, I can't seem to find an example anywhere that works for me. Basically, I want my client to…
harrisonlee
  • 5,068
  • 4
  • 21
  • 20
383
votes
25 answers

HttpClient won't import in Android Studio

I have a simple class written in Android Studio: package com.mysite.myapp; import org.apache.http.client.HttpClient; public class Whatever { public void headBangingAgainstTheWallExample () { HttpClient client = new…
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
192
votes
13 answers

How can I get an HTTP response body as a string?

I know there used to be a way to get it with Apache Commons as documented here: http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/HttpMethod.html ...and an example here: http://www.kodejava.org/examples/416.html ...but I…
Daniel Shaulov
  • 2,354
  • 2
  • 16
  • 25
181
votes
9 answers

Deprecated Java HttpClient - How hard can it be?

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…
Basic
  • 26,321
  • 24
  • 115
  • 201
165
votes
25 answers

How to ignore SSL certificate errors in Apache HttpClient 4.0

How do I bypass invalid SSL certificate errors with Apache HttpClient 4.0?
Viet
  • 17,944
  • 33
  • 103
  • 135
147
votes
5 answers

JsonParseException : Illegal unquoted character ((CTRL-CHAR, code 10)

I'm trying to use org.apache.httpcomponents to consume a Rest API, which will post JSON format data to API. I get this exception: Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to…
jian zhong
  • 1,471
  • 2
  • 9
  • 4
122
votes
8 answers

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

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…
Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147
87
votes
7 answers

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

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…
Oceanic
  • 1,418
  • 2
  • 12
  • 19
82
votes
3 answers

Apache HttpClient making multipart form post

I'm pretty green to HttpClient and I'm finding the lack of (and or blatantly incorrect) documentation extremely frustrating. I'm trying to implement the following post (listed below) with Apache Http Client, but have no idea how to actually do it. …
Russ
  • 1,996
  • 3
  • 19
  • 31
74
votes
12 answers

HttpClient 4.0.1 - how to release connection?

I have a loop over a bunch of URLs, for each one I'm doing the following: private String doQuery(String url) { HttpGet httpGet = new HttpGet(url); setDefaultHeaders(httpGet); // static method HttpResponse response =…
Richard H
  • 38,037
  • 37
  • 111
  • 138
70
votes
9 answers

How to prevent hangs on SocketInputStream.socketRead0 in Java?

Performing millions of HTTP requests with different Java libraries gives me threads hung on: java.net.SocketInputStream.socketRead0() which is a native function. I tried to set up the Apache Http Client and RequestConfig to have timeouts on (I…
Piotr Müller
  • 5,323
  • 5
  • 55
  • 82
67
votes
2 answers

Write in body request with HttpClient

I want to write the body of a request with XML content-type but I don't know how with HttpClient Object ( http://hc.apache.org/httpclient-3.x/apidocs/index.html ) DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpRequest = new…
Tata2
  • 893
  • 2
  • 8
  • 14
63
votes
5 answers

How to get HttpClient returning status code and response body?

I am trying to get Apache HttpClient to fire an HTTP request, and then display the HTTP response code (200, 404, 500, etc.) as well as the HTTP response body (text string). It is important to note that I am using v4.2.2 because most HttpClient…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
59
votes
12 answers

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

public HttpClientVM() { BasicHttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 10); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); …
Liu
  • 591
  • 1
  • 4
  • 3
59
votes
7 answers

Apache HttpClient timeout

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…
Rosty Kerei
  • 1,014
  • 1
  • 9
  • 16
1
2 3
99 100