0

对以下网址有疑问:http: //www.mix1011.com.au/m_app/entertainment/zooey-deschanel-no-bangs

我可以从我的笔记本电脑访问 url,但是当我测试我的移动应用程序时,它给了我 404 错误......嗯,我的理解是该网站限制了从移动设备的访问。

你能解释一下如何解决这个问题吗?

4

1 回答 1

3

这并不是说访问受到限制。正在发生的事情是它重定向到没有您要查找的页面的移动站点。当您尝试从移动浏览器访问您的 URL 时,会发送带有以下数据的 302 重定向:

HTTP/1.1 302 Found
Connection: close
Date: Sat, 11 May 2013 20:45:46 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Server: Live6
X-AspNet-Version: 2.0.50727
Location: http://m.mix1011.com.au/m/m_app/entertainment/zooey-deschanel-no-bangs
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 187

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://m.mix1011.com.au/m/m_app/entertainment/zooey-deschanel-no-bangs">here</a>.</h2>
</body></html>

但是,该网页在 m.mix1011.com.au 上不存在,因此在该域上返回 404:

HTTP/1.1 404 Not Found
Connection  close
Date    Sat, 11 May 2013 20:45:46 GMT
Server  Microsoft-IIS/6.0
X-Powered-By    ASP.NET
Server  Live7
X-AspNet-Version    2.0.50727
Cache-Control   private
Content-Length  0

大多数 HTTP 代理都允许您监视这种情况——我使用了Charles Proxy。在 iPhone 模拟器中访问网页时让它运行。您还可以使用 Firefox 并将浏览器的用户代理更改为 Mobile Safari。

您可以通过更改用户代理来解决此问题(假设您使用的是 UIWebView):

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Your user agent", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; 
于 2013-05-11T20:50:00.363 回答