apache-httpclient-4.x

What is the difference between the setConnectionTimeout , setSoTimeout and “http.connection-manager.timeout” in apache HttpClient API

爷,独闯天下 提交于 2019-11-28 15:35:34
What is the difference between the three(marked as comments) : MultiThreadedHttpConnectionManager connManag = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams managParams = connManag.getParams(); managParams.setConnectionTimeout(connectiontimeout); // 1 managParams.setSoTimeout(sotimeout); //2 HttpMethodBase baseMethod = null; try { HttpClient client = new HttpClient(connManag); client.getParams().setParameter("http.connection-manager.timeout", poolTimeout); //3 baseMethod = new GetMethod(…); int statusCode = client.executeMethod(…); … } catch (ConnectTimeoutException cte

Apache HTTPClient DigestAuth doesn't forward “opaque” value from Challenge

╄→尐↘猪︶ㄣ 提交于 2019-11-28 14:37:13
I'm trying to use Digest authentication with HTTP Client against a 3rd-party web service that I don't control. I started out with the sample code from here: http://hc.apache.org/httpcomponents-client-4.5.x/httpclient/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java I got it working against httpbin.org , before attempting the next step described below. It appears that the target 3rd-party service that I'm using requires the opaque value to be copied from the WWW-Authentication header on the initial response to the Authorization header on the next request, as

How to switch from HttpClient to HttpUrlConnection?

偶尔善良 提交于 2019-11-28 12:40:21
I am creating an Android application and I send data from Android application to servlet through HttpClient. I use HttpPost method. I read in Android developer site that Apache HttpClient library has some bug in Android Froyo 2.2 and after all it's good practice to use HttpUrlConnection instead HttpPost. So I want to convert my HttpPost code to HttpUrlConnectio but don't know how. I am posting my Android code as well as servlet code here Android code private String postData(String valueIWantToSend[]) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient();

Android HttpClient, DefaultHttpClient, HttpPost

◇◆丶佛笑我妖孽 提交于 2019-11-28 11:23:33
How would I send a string data ( JSONObject.toString() ) to a url. I want to write a static method in a util class to do this. I want the method signature to be as follows public static String postData (String url, String postData) throws SomeCustomException What should be the format of the string url The return String is the response from the server in as a string representation of json data. EDIT Present connection util package my.package; import my.package.exceptions.CustomException; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net

HttpClient.getParams() deprecated. What should I use instead?

别等时光非礼了梦想. 提交于 2019-11-28 08:54:54
I am using apache-httpclient-4.3. I would analyze a http request, in particular the query string parameters, but @Deprecated public HttpParams getParams() Deprecated. (4.3) use constructor parameters of configuration API provided by HttpClient I am not sure to understand what this means. I should use the constructor parameters of some configuration API (what's that? HostConfiguration is no more available as class). But during the construction phase I directly pass the query parameters through the url: HttpGet request = new HttpGet("http://example.com/?var1=value1&var2=value2"); I can't find a

RestTemplate vs Apache Http Client for production code in spring project

别说谁变了你拦得住时间么 提交于 2019-11-28 07:16:07
we have a Spring project that is about to go into production. Currently, the project is using Apache Http Client . There is a thought of using RestTemplate as HttpClient . I am digging around to see any notable advantage of using RestTemplate over Apache's . Also, it would be interesting to know what HTTP transport does RestTemplate in its implementation. Apache Http Client has been used by several groups for many years and has a good reputation. would we be risking moving to RestTemplate ? Further, this blog points that RestTemplate needs to be configured for production, although the

How do I properly import HttpClient from org.apache on Android using gradle build file?

非 Y 不嫁゛ 提交于 2019-11-28 06:44:29
I am seeing this error when I try to run "gradle build" WARNING: Dependency org.apache.httpcomponents:httpclient:4.2.3 is ignored for the default configuration as it may be conflicting with the internal version provided by Android. In case of problem, please repackage with jarjar to change the class packages :prepareFreeDebugDependencies :compileFreeDebugAidl UP-TO-DATE :generateFreeDebugBuildConfig UP-TO-DATE :mergeFreeDebugAssets UP-TO-DATE :compileFreeDebugRenderscript UP-TO-DATE :mergeFreeDebugResources UP-TO-DATE :processFreeDebugManifest UP-TO-DATE :processFreeDebugResources UP-TO-DATE

RestTemplate with Basic Auth in Spring 3.1

与世无争的帅哥 提交于 2019-11-28 05:33:18
We were using RestTemplate with xml configuration in Spring 3.0 and it was working perfectly fine. <bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"> <!-- <constructor-arg ref="httpClientParams"/> --> </bean> <bean id="httpClientFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory"> <constructor-arg ref="httpClient"/> </bean> <bean id="restTemplate" name="restTemplate" class="org.springframework.web.client.RestTemplate" autowire-candidate="true"> <constructor-arg ref="httpClientFactory" /> <property name="messageConverters"> <list> <bean class=

How to use Socks 5 proxy with Apache HTTP Client 4?

走远了吗. 提交于 2019-11-28 05:02:53
I'm trying to create app that sends HTTP requests via Apache HC 4 via SOCKS5 proxy. I can not use app-global proxy, because app is multi-threaded (I need different proxy for each HttpClient instance). I've found no examples of SOCKS5 usage with HC4. How can I use it? ok2c SOCK is a TCP/IP level proxy protocol, not HTTP. It is not supported by HttpClient out of the box. One can customize HttpClient to establish connections via a SOCKS proxy by using a custom connection socket factory EDIT: changes to SSL instead of plain sockets Registry<ConnectionSocketFactory> reg = RegistryBuilder.

How do I save a file downloaded with HttpClient into a specific folder

折月煮酒 提交于 2019-11-28 04:53:51
I am trying to download a PDF file with HttpClient. I am able to get the file but i am not sure how to convert the bytes into a a PDF and store it somewhere on the system I have the following code, How can I store it as a PDF? public ???? getFile(String url) throws ClientProtocolException, IOException{ HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); InputStream inputStream = entity.getContent(); // How do I write it? } return null; } Eng.Fouad