apache-httpclient-4.x

What is a good way to share a session between two HTTPClients in a Java program?

半城伤御伤魂 提交于 2019-12-25 02:03:30
问题 I have been developing an Android/Java application that opens up two simultaneous Apache HTTP connections. I have been developing a Chat application, and one connection is almost always running (the server was long polling; it would only respond once changes were made), and a second request to send data to the same site, using the same Session (due to being "logged in") was needed. After plenty of searching on StackOverflow, I have not found a good way to do this. How can this be accomplished

Gradle rename maven dependency package (HttpComponents, Android)

前提是你 提交于 2019-12-24 16:25:30
问题 Using and Choosing way to make HTTP(S) requests on Android is a long-time pain. Although Google wants us to use HttpURLConnection, there are those who prefer to use HttpClient instead. There is this library, https://code.google.com/p/httpclientandroidlib/ with packaging script. I'd rather use something more integrated with Android build environment. Is there possibility to use Gradle to repackage Maven dependency (whole tree, including httpclient, httpcomponents, httpmime, ...) in the same

HttpClient Get images from response

筅森魡賤 提交于 2019-12-24 12:18:08
问题 I'm using Apache HttpClient to perform GET/POST requests, I was wondering if you could save the images loaded/retrieved by a response, without having to download them again with their URLs. This question has been asked like one year ago, but no one answered: Can I get cached images using HttpClient? I tried: CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpget = new HttpGet(url); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response

Importing PEM certificate into Java KeyStore programmatically

怎甘沉沦 提交于 2019-12-24 11:17:32
问题 I have a client certificate composed of two files (.crt and .key) which I wish to import to a java KeyStore to then use in a SSLContext to sent HTTP requests with Apache's HTTPClient. However, I can't seem to find a way to do this programmatically, most other questions I've found either point to external tools or aren't fit for my case. My certificate is encoded with the typical 'BEGIN CERTIFICATE' followed by a Base64 encoded string, and the key with 'BEGIN RSA PRIVATE KEY' and then another

setting socket timeout in both RequestConfig and SocketConfig works differently for HTTP and HTTPS

喜你入骨 提交于 2019-12-24 08:16:33
问题 I have set socket timeout in SocketConfig and set SocketConfig to connection manager as connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(soTimeout).build()) And overwriting the socket timeout value for individual requests by setting it in RequestConfig as httpRequest.setConfig(RequestConfig.copy(defaultRequestConfig).setSocketTimeout(timeout).build()) Reference link. For all http requests, the new value set using RequestConfig is overwriting the old value as expected. But

Unit testing DefaultHttpRequestRetryHandler

拥有回忆 提交于 2019-12-24 06:03:36
问题 I'm working on some legacy code that stores files to a remote server. I'd like to use Apache's DefaultHttpRequestRetryHandler to implement a retry logic. A simplified version of the implementation is shown below. How do I test my retry logic? I was able to manually test it by overriding retryRequest() in the DefaultHttpRequestRetryHandler class but an automated way would be nice. (I'm using Spock to test.) private CloseableHttpClient getHttpClient() { DefaultHttpRequestRetryHandler

Disable NTLM on Apache HttpClient 4.3.6

可紊 提交于 2019-12-24 02:57:43
问题 I am trying to make a HttpClient to a service that support NTLM and Basic auth. In my case NTLM will not work, because the machine HttpClient is on is under a different domain to the service (thanks a corporate decision to very slowly migrate the name of the domain being used...). However it seems HttpClient will still try to use it anyway. CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new

Will Apache HttpClient execute throw an IOException on ALL HTTP 5XX errors?

女生的网名这么多〃 提交于 2019-12-23 12:07:08
问题 The Apache HttpClient docs for the execute(HttpHost target, HttpRequest request) method says: IOException - in case of a problem or the connection was aborted If I catch the IOException, will this catch ALL Server 5xx Errors? try { response = client.execute(httpHost, request); } catch (IOException e) { // throw custom Exception } finally { // close response and client } The reason I'm asking is that after this logic somewhere else down the line we're doing something like the following: if

Apache HttpClient 4.3 SocketConfig.getSoTimeout() vs RequestConfig.getSocketTimeout()

烈酒焚心 提交于 2019-12-23 07:56:09
问题 When building a CloseableHttpClient in Apache HttpClient 4.3, I can use SocketConfig.custom().setSoTimeout(soTimeout).build() and send it to the setDefaultSocketConfig() method of my connection manager. I can also use RequestConfig.custom().setSocketTimeout(socketTimeout).build() and send it to the setDefaultRequestConfig() method of my http client builder. Will these have the same end effect or different end effects? 回答1: Socket timeout in SocketConfig represents the default value applied to

Cannot process url with vertical/pipe bar in Java/Apache HttpClient

最后都变了- 提交于 2019-12-23 07:39:15
问题 If I want to process this url for example: post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList|401814|1"); Java/Apache won't let me because it says that the vertical bar ("|") is illegal. escaping it with double slashes doesn't work as well: post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList\\|401814\\|1"); ^ that doesn't work as well. Any suggestions how to make this work? 回答1: try with URLEncoder.encode() Note: you should encode string which is after