1

これは私が今まで見た中で最も奇妙なものです。私は iPhone 5 と iPhone 5s を持っており、どちらも iOS 7.1.2 で、完全にクリーンです。次のコードを実行します。

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 は、探している正しいページ ソースと、シミュレーターから取得したものと同じものを返します。ヘッダーは次のようになります。

"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 ヘッダーからわかるように、何か違うものを返します。

"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 を発見しました!? 同じ Wi-Fi ネットワークでテストしていますが、電話は AT&T と Verizon サービスに分割されています。1 Verizon は動作していますが、他は動作していません。AT&T はすべて動作しています。

アップデート:

私は問題を解決しました。ここで、自分が何をしたかを理解するための助けが必要です:/ヘッダーの違いが次の行であることに気付きました"Content-Encoding" = gzip。コードに次の行を設定しました。

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

要求は期待どおりに機能するようになりましたが、なぜそれを行う必要があるのでしょうか? これは新しい機能ではありません。

4

1 に答える 1