我有一个可以从桌面浏览器访问的 url,没有任何问题。但是当我从 Android 访问它时,Http Response 是 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 浏览器上访问 URL,它也显示 404 错误。
有没有其他方法可以做到这一点?