iPhone 5 和 5s 上的 NSHTTPURLResponse 不同 [英] NSHTTPURLResponse different on iPhone 5 vs 5s

查看:70
本文介绍了iPhone 5 和 5s 上的 NSHTTPURLResponse 不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我见过的最奇怪的事情.我有一部 iPhone 5 和一部 iPhone 5s,都在 iOS 7.1.2 上,完全干净.我运行以下代码:

This is officially the weirdest thing I've ever seen. I have an iPhone 5 and an iPhone 5s, both on iOS 7.1.2, completely clean. I run the following code:

NSString *userAgent = @"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3";
NSURL *url = [NSURL URLWithString: deviceString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSDictionary *dict = [response allHeaderFields];
NSLog(@"Status code: %d",[response statusCode]);
NSLog(@"Headers:\n %@",dict.description);
NSLog(@"Error: %@",error.description);
NSLog(@"Response data: %@",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);

iPhone 5s 返回了我正在寻找的正确页面源,与我从模拟器中得到的相同.标题如下所示:

The iPhone 5s returns the correct page source that I am looking for, and the same one I get from the simulator. The header looks like this:

"Alternate-Protocol" = "80:quic";
"Cache-Control" = "no-cache";
"Content-Encoding" = gzip;
"Content-Length" = 5627;
"Content-Type" = "text/plain; charset=utf-8";
Date = "Fri, 01 Aug 2014 17:21:40 GMT";
Expires = "Tue, 27 Apr 1971 19:44:06 EST";
P3P = "CP=\"This is not a P3P policy! See http://support.google.com/accounts/bin/answer.py?answer=151657&hl=en for more info.\"";
Server = "gwiseguy/2.0";
"Set-Cookie" = "YSC=oohlyqgkgwg; path=/; domain=.youtube.com; httponly";
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = SAMEORIGIN;
"X-XSS-Protection" = "1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube";

iPhone 5 返回了一些不同的东西,而且从 Content-Length 标头中可以看出明显更短:

The iPhone 5 returns something different, and significantly shorter as you can see from the Content-Length header:

"Alternate-Protocol" = "80:quic";
"Cache-Control" = "no-cache";
"Content-Length" = 767;
"Content-Type" = "text/html; charset=utf-8";
Date = "Fri, 01 Aug 2014 17:23:06 GMT";
Expires = "Tue, 27 Apr 1971 19:44:06 EST";
P3P = "CP=\"This is not a P3P policy! See http://support.google.com/accounts/bin/answer.py?answer=151657&hl=en for more info.\"";
Server = "gwiseguy/2.0";
"Set-Cookie" = "YSC=2KFSqyO4p1k; path=/; domain=.youtube.com; httponly";
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = SAMEORIGIN;
"X-XSS-Protection" = "1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube";

我很困惑.

我现在发现了一个可以正常工作的 iPhone 5 和一个不能正常工作的 iPhone 5s!?我们正在同一个 wifi 网络上进行测试,但电话分为 AT&T 和 Verizon 服务.1 Verizon 正在工作,其他人则没有.所有 AT&T 都在工作.

I have now discovered an iPhone 5 that is working properly and an iPhone 5s that is not!? We are testing on the same wifi network but the phones are split between AT&T and Verizon service. 1 Verizon is working, the others are not. All AT&T is working.

更新:

我已经解决了这个问题.现在我需要一些帮助来理解我做了什么:/我注意到标题之间的区别是 "Content-Encoding" = gzip 所以我在我的代码中设置了这一行:

I have solved the problem. Now i need some help understanding what I did :/ I noticed the difference between the headers was the line "Content-Encoding" = gzip So I set this line in my code:

    [request setValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];

现在请求按预期工作,但为什么我需要这样做?我过去没有,这不是新功能.

Now the request works as expected, but why do I need to do that? I haven't in the past, this is not a new feature.

推荐答案

我注意到标题之间的区别在于Content-Encoding" = gzip 这一行所以我在我的代码中设置了这一行:

I noticed the difference between the headers was the line "Content-Encoding" = gzip So I set this line in my code:

 [request setValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];

现在请求按预期工作.

这篇关于iPhone 5 和 5s 上的 NSHTTPURLResponse 不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆