apache-httpclient-4.x

Make HttpClient consume “garbage” before next request

為{幸葍}努か 提交于 2020-01-05 02:32:54
问题 I am using Apache HttpClient 4.5.1 to send some requests to our server. To improve performance I'd like to reuse the same HttpClient instance for all those requests. The requests (mostly) happen in sequential order, so there is no multi-threading involved. Unfortunately some of the servers endpoints are faulty. They are returning a HTTP 204 (No content), but some data in the response body anyway. Even though this has been fixed in the latest release, we will have to deal with the older

Cookies getting ignored in Apache httpclient 4.4

房东的猫 提交于 2020-01-04 15:57:14
问题 I upgraded Apache http client from 4.3.6 to 4.4 and observed that cookies are getting ignored. Any idea how to get cookie working in 4.4? Edit: code snippet CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(new BasicClientCookie("name", "value")); RequestConfig config = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build(); HttpClient client = HttpClientBuilder.create() .disableRedirectHandling() .setDefaultRequestConfig(config) .setDefaultCookieStore

Apache HttpClient is throwng HTTP 500s but can't reproduce in a browser

不打扰是莪最后的温柔 提交于 2020-01-03 12:44:43
问题 Using HttpClient 4.1.3, I've written the following code: HttpClient httpClient = HttpClientFactory.newHttpClient(); HttpGet httpGet = new HttpGet("some/url/to/hit"); HttpResponse httpResp = httpClient.execute(httpGet); int statusCode = httpResp.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) throw new Exception(/* ... */); That's getting HTTP 500 responses (as found in the httpResp.getStatusLine().getStatusCode() ) from a particular URL and throwing the exception. The

Apache HTTPClient sends no client cert during mutual authentication

微笑、不失礼 提交于 2020-01-03 05:04:26
问题 I'm getting a handshake_failed exception when making a RESTful post call to an API that requires mutual authentication. I have verified with an engineer on the other side who is watching a stack trace that the server-side certs are exchanged and accepted by my client without issue, but when the server requests the client-side cert my side doesn't provide that and the handshake terminates. The thing is I have no idea how to verify whether SSLSocketFactory is unable to identify the right

Header values overwritten on redirect in HTTPClient

戏子无情 提交于 2020-01-03 03:08:06
问题 I'm using httpclient 4.2.5 to make http requests which have to handle redirects as well. Here is a little example to understand the context: A sends http request (using httpclient 4.2.5) to B B sends 302 redirect (containing url to C) back to A A follows redirect to C C retrieves request URL and do some work with it If C parses the request URL by request.getRequestURL() (HttpServlet API) it contains e.g. host and port of the original request from step 1, which is wrong. The problem exists in

JSON: “Unexpected character (<) at position 0”

纵然是瞬间 提交于 2020-01-02 18:17:21
问题 Here's the twitch.tv api request to get channel summary: http://api.justin.tv/api/streams/summary.json?channel=mychannel . If I post it via browser, I get correct results. But programmatically I receive an exception during result parsing. I use apache HttpClient to send requests and receive responses. And JSON-Simple to parse JSON content. This is how I try to get JSON from response according to api: HttpClient httpClient = HttpClients.createDefault(); HttpGet getRequest = new HttpGet(new URL

how to translate curl -X post into java

泪湿孤枕 提交于 2020-01-02 08:04:32
问题 I am trying to translate a curl command into Java (using Apache HttpClient 4.x): export APPLICATION_ID=SOME_ID export REST_API_KEY=SOME_KEY curl -i -X POST \ -H "X-Parse-Application-Id: ${APPLICATION_ID}" \ -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \ -H "Content-Type: image/png" \ --data-binary @/Users/thomas/Desktop/greep-small.png \ https://api.parse.com/1/files/greep.png but I get the following error: {"error":"unauthorized"}. This is what my java code looks like: DefaultHttpClient

Authenticating a single request with httpclient 4.x

筅森魡賤 提交于 2020-01-02 07:44:10
问题 I have an HttpClient instance that's shared by a number of threads. I would like to use it to make a single authenticated request. Because only the single request should be authenticated, I don't want to modify the HttpClient instance as described in the documentation. Here's what I've worked out instead, which isn't working. From what I can tell, it doesn't look like the CredentialsProvider is being used at all. Any tips? HttpContext context = null; if(feedSpec.isAuthenticated()) { context =

How to use HttpAsyncClient with multithreaded operation?

隐身守侯 提交于 2020-01-02 06:06:10
问题 Closely related to this question: How to use HttpClient with multithreaded operation?, I'm wondering if apache HttpAsyncClient is thread safe, or if it, too, requires the use of a MultiThreadedHttpConnectionManager, or a ThreadSafeClientConnManager. If it does require such a connection manager, does one exist in the async libraries? I was able to find a PoolingClientAsyncConnectionManager in the async libraries, but I'm not sure if that's what I need. Alternately, I was thinking of using

HttpClient 4.1.x error for self signed certificate (javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated )

蓝咒 提交于 2020-01-01 20:00:49
问题 I am trying to configure the Tomcat6 with self-signed certificates with clientAuth=true & then to call the Tomcat server on client side using HttpClient 4.1.x. I followed the instruction provided in the http://virgo47.wordpress.com/2010/08/23/tomcat-web-application-with-ssl-client-certificates/ & it is working fine as expected when I am testing from the browser or from the openssl client (I ran the command "openssl s_client -cert client.crt -key client.key -CAfile ca.crt -connect localhost