我有一个可以从桌面浏览器访问的网址没有任何问题。但是当我从Android访问它时,Http响应是404。
知道问题是什么。我已设置用户代理,如下所示:
final HttpParams params = new BasicHttpParams();
HttpClientParams.setRedirecting(params, true);
HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY);
final DefaultHttpClient client = new DefaultHttpClient(params);
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:23.0) Gecko/20131011 Firefox/23.0");
final HttpGet getRequest = new HttpGet(url);
try {
HttpResponse response = client.execute(getRequest);
//check 200 OK for success
final int statusCode = response.getStatusLine().getStatusCode();
//how to handle redirects?
if (statusCode != HttpStatus.SC_OK) {
Log.w("msg", "Error " + statusCode);
return null;
}
我还尝试直接在Android浏览器上访问该网址,它也显示404错误。
还有其他办法吗?
提前致谢