NSURLConnection 在 iOS 设备上重定向,但在模拟器上不重定向
当我向特定网站发出请求时,我会在模拟器上收到所需的 XML 响应,但会在设备上收到重定向页面。我认为这是因为它检测到我正在使用移动浏览器(通过 Mobile Safari 会出现类似的结果),但我将请求的用户代理字符串设置为我的笔记本电脑浏览器的 UA 并清空其余部分(我也尝试仅设置 UA):
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setAllHTTPHeaderFields:[NSDictionary dictionaryWithObject:@"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11" forKey:@"User-Agent"]];
NSURLConnection* _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
网站如何仍然检测到我正在使用移动浏览器?相同的 GET 通过零信息的 telnet 工作,这意味着默认响应是桌面版本。
When I make a request to a particular website, I get the XML response as desired on the simulator but I get a redirect page on the device. I think this is because it is detecting that I am using a mobile browser (similar results occur through Mobile Safari), but I'm setting the user agent string of the request to my laptop browser's UA and blanking the rest (I've also tried setting just the UA):
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setAllHTTPHeaderFields:[NSDictionary dictionaryWithObject:@"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11" forKey:@"User-Agent"]];
NSURLConnection* _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
How could the website still be detecting that I'm using a mobile browser? The same GET works through telnet with zero information, which implies that the default response is the desktop version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,Mobile Safari 会在模拟器中自动重定向/重新协商 http->https,但不会在设备上执行此操作。
Turns out Mobile Safari will automatically redirect/renegotiate http->https in the simulator, but won't do it on the device.