apache-httpclient-4.x

How to use DefaultHttpClient in Android? [closed]

僤鯓⒐⒋嵵緔 提交于 2019-11-29 02:21:25
How to use DefaultHttpClient in Android? I suggest reading the tutorials provided with android-api. Here is some random example which uses DefaultHttpClient, found by simple text-search in examples-folder. EDIT: The sample-source was not intended to show something. It just requested the content of the url and stored it as string. Here is an example which shows what it loaded (as long as it is string-data, like an html-, css- or javascript-file): main.xml <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textview"

How to stream response body with apache HttpClient

亡梦爱人 提交于 2019-11-29 02:18:17
There's an api I need to perform octet-streaming from which does not have a length. It is just a stream of real time data. The issue that I'm having is that when I make my request, it seems to try to wait out for the end of the content before reading information into the inputstream, however it's not seeing the end of the content and timingout with NoHttpResponse exception. Below is a simplified version of my code: private static HttpPost getPostRequest() { // Build uri URI uri = new URIBuilder() .setScheme("https") .setHost(entity.getStreamUrl()) .setPath("/") .build(); // Create http http

Apache HttpClient 4.3.5 set proxy

旧街凉风 提交于 2019-11-29 01:15:33
问题 It seems that I can specify the proxy when I construct new HttpClient with: HttpHost proxy = new HttpHost("someproxy", 8080); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); CloseableHttpClient httpclient = HttpClients.custom() .setRoutePlanner(routePlanner) .build(); taken from http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e475 Is it possible to modify existing client's proxy settings. 回答1: You can create your own implementation of

HttpClient fails with Handshake Failed in Android 5.0 Lollipop

两盒软妹~` 提交于 2019-11-29 00:32:36
问题 DefaultHttpClient in Android 5.0 Lollipop seems to be broken. It can not set the connection to some sites that were successfully set by previous versions of Android. For example I try to connect to https://uralsg.megafon.ru //Create httpclient like in https://stackoverflow.com/questions/18523784/ssl-tls-protocols-and-cipher-suites-with-the-androidhttpclient HttpClient client = new DefaultHttpClient(manager, params); HttpGet httpGet = new HttpGet("https://uralsg.megafon.ru"); HttpResponse

Android Rest Client

社会主义新天地 提交于 2019-11-29 00:29:01
I found so many samples for requesting a REST API, but all together are confusing, can some one please explain me a way to use http requests. My Requirement is, I want to get data from a REST API by providing username, pwd and a key. What I have Used was, HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("REST API url"); post.setHeader("Content-type", "application/json"); JSONObject obj = new JSONObject(); obj.put("username", "un"); obj.put("pwd", "password"); obj.put("key","123456"); post.setEntity(new StringEntity(obj.toString(), "UTF-8")); HttpResponse response =

Tomcat 7 getting SSLv2Hello is disabled error when trying to make client server ssl authntication

坚强是说给别人听的谎言 提交于 2019-11-29 00:07:01
I have tried to setup a self-signed TLS configuration for both client and server where the server is Tomcat 7 and the client is Apache httpclient 4.1. The server configuration is taken from this here and the client code is taken from here . My tomcat configuration looks like this: <Connector clientAuth="true" port="8443" minSpareThreads="5" maxSpareThreads="75" enableLookups="true" disableUploadTimeout="true" acceptCount="100" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" keystoreFile="keys/server.jks" keystoreType="JKS" keystorePass="password" truststoreFile="keys/server.jks

Basic Authentication with RestTemplate (3.1)

谁说胖子不能爱 提交于 2019-11-29 00:02:45
I am trying to reproduce the following curl command using Java: curl -v -u user:pass http://myapp.com/api This command returns some JSON data. My buggy Java implementation is as follows: @Test public void callTest() { RestTemplate restTemplate = createRestTemplate("user", "pass"); URI uri = new URI("http://myapp.com/api"); String res = restTemplate.getForObject(uri, String.class); } private static RestTemplate createRestTemplate(String username, String password) { UsernamePasswordCredentials cred = new UsernamePasswordCredentials(username, password); BasicCredentialsProvider cp = new

How can I disable default request headers from apache httpclient 4?

旧街凉风 提交于 2019-11-28 23:36:22
I am using apache common httpclient 4.3.3 to make http 1.0 request. Here is how I make the request HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(url); post.setProtocolVersion(new ProtocolVersion("HTTP", 1, 0)); // trying to remove default headers but it doesn't work post.removeHeaders("User-Agent"); post.removeHeaders("Accept-Encoding"); post.removeHeaders("Connection"); post.setEntity(new ByteArrayEntity(ba) ); HttpResponse response = client.execute(post); However, i can see that there are other headers automatically added to my request to the server

Apache PoolingHttpClientConnectionManager throwing illegal state exception

对着背影说爱祢 提交于 2019-11-28 23:22:30
Here is how I use it - private static final PoolingHttpClientConnectionManager connPool; static { connPool = new PoolingHttpClientConnectionManager(); // Increase max total connection to 200 connPool.setMaxTotal(200);//configurable through app.properties // Increase default max connection per route to 50 connPool.setDefaultMaxPerRoute(20);//configurable through app.properties } CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connPool) .build(); ALso I have put a finally block around http GET - finally { try { httpClient.close(); } catch (IOException e) { LOGGER