apache-httpclient-4.x

SSLHandshakeException: hostname in certificate didn't match

假如想象 提交于 2019-12-06 07:48:07
问题 I am writing a system that must make a multipart post to a server (a third-party program called ARX that is currently running on localhost during the development) that has a self-signed certificate. I tried to find its certificate, but can only find three different jks files; server.jks , servertrust.jks and serverca.jks . I have tried to use the System.setProperty("javax.net.ssl.trustStore", "Program Files\\<path>\\jksfile") with each of the jks files. However; when I do, I get the following

Timeout between request retries Apache HttpClient

僤鯓⒐⒋嵵緔 提交于 2019-12-06 07:20:15
问题 Could somebody share how to configure modern HttpClient 4.5.3 to retry failed requests and wait for some time before each retry? So far it looks like I got it correctly that .setRetryHandler(new DefaultHttpRequestRetryHandler(X, false)) will allow to retry requests X times. But I cannot understand how to configure backoff: .setConnectionBackoffStrategy() / .setBackoffManager() according to JavaDocs regulate something else, not timeout between retries. 回答1: About the dynamic delay, I want to

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

自闭症网瘾萝莉.ら 提交于 2019-12-06 05:32:56
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("http://api.justin.tv/api/streams/summary.json?channel=mychannel").toURI()); getRequest.addHeader(

Apache http client defaults don't work with sni

人走茶凉 提交于 2019-12-06 05:19:01
问题 PRIMARY QUESTION Is there a bug I'm not aware of with the latest 4.x apache http client? or a setting that I'm missing to get sni to work? On/in the same jvm (in this case 1.7.0_45). I run the following two pieces of code to pull an https url that requires SNI for it to connect correctly. The 1st piece of code uses java's built in java.net.* approach, and the 2nd piece of code uses org.apache.http.* (version 4.5) approach. Approach with java.net.* public final class JavaNetHitApi extends

Migrate from Commons HttpClient to HttpComponents Client

元气小坏坏 提交于 2019-12-06 03:52:38
I would like to migrate from Commons HttpClient (3.x) to HttpComponents Client (4.x) but having difficulty how to handle redirects. The code works properly under Commons HttpClient but breaks when migrated to HttpComponents Client. Some of the links get undesirable redirects but when I set "http.protocol.handle-redirects" to 'false' a large number links stop working altogether. Commons HttpClient 3.x: private static HttpClient httpClient = null; private static MultiThreadedHttpConnectionManager connectionManager = null; private static final long MAX_CONNECTION_IDLE_TIME = 60000; //

how to translate curl -X post into java

怎甘沉沦 提交于 2019-12-06 02:57:00
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 httpclient = new DefaultHttpClient(); HttpHost targetHost = new HttpHost("localhost", 80, "http"); httpclient

Parsing JSON from HttpClient request using JSON.org parser

雨燕双飞 提交于 2019-12-06 01:35:30
问题 I am trying to parse JSON using a Notes agent, JSON is fetched using Apache HttpClient. Here is the code that return the JSON import lotus.domino.*; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; Session session = getSession(); AgentContext agentContext = session.getAgentContext(); HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new

Multi-part POST with file and string in HTTPClient 4.1

荒凉一梦 提交于 2019-12-06 01:27:00
问题 I need to create Multi-part POST request containing fields: update[image_title] = String update[image] = image-data itself . As you can see both are in associative array called "update". How could I do it with HTTPClient 4.1, because I found only examples for 3.x line of this library. Thank you in advance. 回答1: Probably too late but might help someone. I had the exact same issue. Assuming that you have a file object which has necessary information about the image HttpPost post = new HttpPost

Configuring Apache HttpClient to access service through proxy/load-balancer (overriding Host header)

喜夏-厌秋 提交于 2019-12-05 21:18:13
I am having a problem getting the Apache HttpClient to connect to a service external to my virtualised development environment. To access the internet (e.g. api.twitter.com) I need to call a local URL (e.g. api.twitter.com.dev.mycompany.net), which then forwards the request to real host. The problem is, that to whatever request I send, I get a 404 Not Found response. I have tried debugging it using wget, and it appears the problem is, that the destination server identifies the desired resource by using both the request URL and the hostname in the Host header. Since the hostname does not match,

Java not sending client certificate

人盡茶涼 提交于 2019-12-05 19:38:02
I'm using HttpClient 4.2.3 on Java 1.7 to connect to a remote server hosted by nginx. My organization uses PKI extensively, and both the remote and the client have certificates issued by a common CA. The server has a signing chain like the following: CN=Server 123, OU=Servers, OU=My Division, O=My Org, C=US CN=My Division CA, OU=My Division, O=My Org, C=US CN=My Org CA, O=My Org, C=US And the client has a signing chain like the following: CN=Client 456, OU=Servers, OU=My Division, O=My Org, C=US CN=My Division CA, OU=My Division, O=My Org, C=US CN=My Org CA, O=My Org, C=US For some reason, the