apache-commons-httpclient
Turning on Logging in HttpClient
I faced same problem today. And I found out a solution for this problem. It’s pretty simple. Just add jcl-over-slf4j dependency to forward JCL logging (Apache Commons Logging) to slf4j. <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.7.5</version> </dependency> After that you can config log file as Log4j Examples. If you use logback you can put the following to … Read more
PostMethod setRequestBody(String) deprecated – why?
The javadoc says: Deprecated. use setRequestEntity(RequestEntity) RequestEntity has a lot of implementors, namely: ByteArrayRequestEntity, FileRequestEntity, InputStreamRequestEntity, MultipartRequestEntity, StringRequestEntity Use the one that suits you: if your xml is in a String, use the StringRequestEntity if it is in a file, use the FileRequestEntity and so on.
Apache HttpClient 4.1 – Proxy Settings
Yes I sorted out my own problem,this line httpclient.getParams().setParameter(“3128”,proxy); should be httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); Complete Example of a Apache HttpClient 4.1, setting proxy can be found below HttpHost proxy = new HttpHost(“ip address”,port number); DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); HttpPost httpost = new HttpPost(url); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair(“param name”, param)); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.ISO_8859_1)); … Read more
Does Apache Commons HttpClient support GZIP?
Apache HttpClient 4.1 supports content compression out of the box along with many other features that were previously considered out of scope.
Without changing code, how to force httpClient to use proxy by environment variables or JVM arguments
in https://issues.apache.org/jira/browse/HTTPCLIENT-1128 SystemDefaultHttpClient was added to ver. 4.2 see http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/SystemDefaultHttpClient.html
Using Apache httpclient for https
I put together this test app to reproduce the issue using the HTTP testing framework from the Apache HttpClient package: ClassLoader cl = HCTest.class.getClassLoader(); URL url = cl.getResource(“test.keystore”); KeyStore keystore = KeyStore.getInstance(“jks”); char[] pwd = “nopassword”.toCharArray(); keystore.load(url.openStream(), pwd); TrustManagerFactory tmf = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm()); tmf.init(keystore); TrustManager[] tm = tmf.getTrustManagers(); KeyManagerFactory kmfactory = KeyManagerFactory.getInstance( KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, pwd); … Read more
Using Apache HttpClient how to set the TIMEOUT on a request and response
I am guessing many people come here because of the title and because the HttpConnectionParams API is deprecated. Using a recent version of Apache HTTP Client, you can set these timeouts using the request params: HttpPost request = new HttpPost(url); RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(TIMEOUT_MILLIS) .setConnectTimeout(TIMEOUT_MILLIS) .setConnectionRequestTimeout(TIMEOUT_MILLIS) .build(); request.setConfig(requestConfig); Alternatively, you can also set this … Read more