I’m using following stupid code to download some data:
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
request.setHeader("User-Agent","Android Browser");
HttpResponse response = client.execute(request);
in=response.getEntity().getContent();
len=(int)response.getEntity().getContentLength();
if (len<=0) return null;
data=new byte[len];
...
Downloading data this way is incredibly slow and often fails with a connection timeout. The same happens on other users devices so the configuration of my network should not be the reason.
On the other hand the given “url” works fine when I type it into a normal browser, it is fast and returns a result nearly immediately. My Android device and the “normal” computer with that browser are running on same WLAN network. So what could be wrong here?
Most probably you do something funny outside of quoted code, could you please run this function and see in the log how long does it take to finish the request?
Well, something is definitely not right here. Could you please open the browser on your phone and try to access the web? If the browser access is equally slow, this it not a problem with your software, maybe your neighbours are microwaving their sausages and disrupting your wifi. However, if the browser opens pages almost instantly (within a second or two), then something is funny with your program. In that case I would create empty HelloWorld project, copy
check_fetch_time()there and try again.