apache-httpcomponents

Handling downloads in Java

不羁岁月 提交于 2019-12-01 17:36:30
How would I be able to handle downloads using HttpResponse in Java? I made an HttpGet request to a specific site - the site returns the file to be downloaded. How can I handle this download? InputStream doesn't seem to be able to handle it (or maybe I'm using it the wrong way.) Assuming you're actually talking about HttpClient , Here's an SSCCE : package com.stackoverflow.q2633002; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache

Handling downloads in Java

孤街醉人 提交于 2019-12-01 17:00:26
问题 How would I be able to handle downloads using HttpResponse in Java? I made an HttpGet request to a specific site - the site returns the file to be downloaded. How can I handle this download? InputStream doesn't seem to be able to handle it (or maybe I'm using it the wrong way.) 回答1: Assuming you're actually talking about HttpClient, Here's an SSCCE: package com.stackoverflow.q2633002; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io

How to find mimetype of response

一个人想着一个人 提交于 2019-12-01 03:24:55
I am working with a GET request made using Apache HTTP client (v4- the latest version; not the older v3)... How do I obtain the mimetype of the response? In the older v3 of apache http client, mime type was obtained using following code-- String mimeType = response.getMimeType(); How do I get the mimetype using v4 of apache http client? A "Content-type" HTTP header should give you mime type information: Header contentType = response.getFirstHeader("Content-Type"); or as Header contentType = response.getEntity().getContentType(); Then you can extract mime type itself as the content-type may

SSLPeerUnverifiedException with httpClient

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 16:04:45
I'm trying to test a secure http connection using self signed certificates... just for development purposes. But I haven't been able to resolve the peer not authenticated exception, of course I have looked at similar posts about this exception and the following one is the current implementation I'm using: public class SelfCertificatesSocketFactory extends SSLSocketFactory { SSLContext sslContext = SSLContext.getInstance("TLS"); public SelfCertificatesSocketFactory(KeyStore trustStore) throws NoSuchAlgorithmException,UnrecoverableKeyException,KeyStoreException,KeyManagementException { super

Java- apache http client- usage examples showing use of cookies and extracting response from HTTPResponse object

▼魔方 西西 提交于 2019-11-30 14:19:13
I am working with apache http client (v4) in a java web app, and I am stuck in the following cases, for which I require simple usage examples-- (1) How to use Cookies with Apache HTTP client, different options available for usage of cookies (2) Extracting charset, mimetype, response headers (as KeyValuePair) and budy (as byte[]) when the response is available in HTTPResponse object. 1)AS for cookies,see that exapmle: httpcomponents-client-4.1.3\examples\org\apache\http\examples\client\ClientCustomContext.java main code: HttpClient httpclient = new DefaultHttpClient(); try { // Create a local

Apache Http Client prints “[read] I/O error: Read timed out”\"

ぐ巨炮叔叔 提交于 2019-11-30 13:02:45
I am using apache http client v4.5 and using it as a REST client. In some cases I recognize an error "[read] I/O error: Read timed out" which comes from the httpclient framework when it reads the received content and shows it as a last message. It seems not to have an impact, however I wonder if somebody has an idea where it is coming from and how it can be solved. According the following thread ( link ) it seems to be an issue with the "mutlithreaded" configuration. However I use only the default configuration of http client and while I am using the version v4 I have no clue how I can set

Connection and connection request timeout

点点圈 提交于 2019-11-30 07:54:27
问题 I am using Http Apache Components to perform the http interactions. I need to adjust my http client. For this purpose I have two parameters: connection timeout and connection request timeout. In library documentation and in source code(no comments were found) I didn't found definition of this terms. I need to know what do they exactly mean. May be they were defined in HTTP protocol documentation but I can't find it. So, my question is what do this two terms mean and how they distinct from

SSLPeerUnverifiedException with httpClient

吃可爱长大的小学妹 提交于 2019-11-29 22:43:40
问题 I'm trying to test a secure http connection using self signed certificates... just for development purposes. But I haven't been able to resolve the peer not authenticated exception, of course I have looked at similar posts about this exception and the following one is the current implementation I'm using: public class SelfCertificatesSocketFactory extends SSLSocketFactory { SSLContext sslContext = SSLContext.getInstance("TLS"); public SelfCertificatesSocketFactory(KeyStore trustStore) throws

Apache HttpComponents HttpClient timeout

风格不统一 提交于 2019-11-29 20:16:43
How do I set the connection timeout in httpcomponents httpclient? I have found the documentation at: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html but it is not clear how these parameters are actually set. Also, an explanation of the difference between SO_TIMEOUT and CONNECTION_TIMEOUT would be helpful. 30thh In version 4.3 of Apache Http Client the configuration was refactored (again). The new way looks like this: RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder.setConnectTimeout(timeout); requestBuilder.setConnectionRequestTimeout

Unsupported record version SSLv2Hello using CloseableHttpClient

筅森魡賤 提交于 2019-11-29 15:52:42
问题 I am trying to make an https call and getting the following error: Unsupported record version SSLv2Hello Can anyone please shed some light on what I'm doing wrong? Thanks for your help. Here is the StackTrace: debug: Unsupported record version SSLv2Hello javax.net.ssl.SSLException: Unsupported record version SSLv2Hello at sun.security.ssl.InputRecord.readV3Record(Unknown Source) at sun.security.ssl.InputRecord.read(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)