There is a URL which opens fine on PC and mobile browser (chrome), but when i try to open it in an android program using below code it gives following error.
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = "";
for (String url : urls) {
//DefaultHttpClient client = new DefaultHttpClient();
HttpClient client = AndroidHttpClient.newInstance("Android");
HttpGet httpGet = new HttpGet(url);
// httpGet.setHeader("User-Agent", "Chrome");
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
on running the code I get an Access Denied error from the server. If I try any other url it works fine. I have tried searching on how to set user-agent to bypass any restrictions put on the server, but could not succeed. Please help.
Additionally I have seen that the header section of the webpage from which this url is called (from browser) contains the below
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="HandheldFriendly" content="true" />
<meta name="MobileOptimized" content="width" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />