简体   繁体   English

NSURLConnection在iOS设备上重定向,但在模拟器上未重定向

[英]NSURLConnection redirected on iOS device, but not on simulator

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. 当我向特定网站发出请求时,我在模拟器上获得了所需的XML响应,但在设备上却获得了一个重定向页面。 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): 我认为这是因为它正在检测到我正在使用移动浏览器(通过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];

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. 相同的GET通过telnet使用零信息进行工作,这意味着默认响应为桌面版本。

事实证明,Mobile Safari会在模拟器中自动重定向/重新协商http-> https,但不会在设备上进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM