Well this question may sounds a little crazy but I just want to save time and engergy. To open a connection needs time and engergy on a mobile device so I want to reuse open connections if possible.
It can happen that I'll need to download files from example.com
and example.net
. Both sites are hosted on the same server/ip so it should be possible to get documents from both documents with just one connection.
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://example.com/robots.txt");
HttpGet get2 = new HttpGet("http://example.net/robots.txt");
URI uri = get.getURI();
HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
ResponseHandler<String> responseHandler = new BasicResponseHandler();
HttpResponse response = client.execute(host, get);
String data = responseHandler.handleResponse(response);
Log.v("test", "Downloaded " + data.length() + " bytes from " + get.getURI().toASCIIString());
response = client.execute(host, get2);
data = responseHandler.handleResponse(response);
Log.v("test", "Downloaded " + data.length() + " bytes from " + get2.getURI().toASCIIString());
The problem is when I don't use that HttpHost
for each call is a new connection established. If I use that both Host
HTTP headers points to the first domain. How can I fix that?