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

2236 questions
406
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
  • 4,798
  • 4
  • 18
  • 20
370
votes
24 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
  • 18,031
  • 39
  • 126
  • 220
176
votes
10 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
  • 25,223
  • 23
  • 108
  • 188
165
votes
14 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,084
  • 2
  • 15
  • 25
142
votes
23 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
  • 16,604
  • 31
  • 94
  • 134
104
votes
4 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,041
  • 2
  • 7
  • 4
95
votes
7 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
  • 19,806
  • 20
  • 87
  • 131
80
votes
6 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,298
  • 1
  • 10
  • 19
80
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,866
  • 3
  • 18
  • 28
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
  • 34,219
  • 33
  • 105
  • 133
62
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
  • 823
  • 2
  • 8
  • 14
60
votes
9 answers

How to prevent hangs on SocketInputStream.socketRead0 in Java?

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)…
Piotr Müller
  • 4,845
  • 3
  • 45
  • 79
59
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
  • 50,141
  • 159
  • 435
  • 728
55
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
  • 914
  • 1
  • 8
  • 14
55
votes
1 answer

How do Jersey-client and Apache HTTP Client compare?

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…
1
2 3
99 100