ウェブサイトからヘッダー情報を返すコードを取得しました。ポート 80 でサービスをシャットダウンし、Web サイトがオフラインの場合でも、アプリは引き続きヘッダー情報を返します。これは、一部のプロバイダーのプロキシによるものです。最初の 3 回は正しく動作します。オンラインでもオフラインでも対応します。リクエストの後、ウェブサイトは常にアプリに対してオンラインになっています。
これは私のコードです:
- (IBAction)fastCheckButton:(id)sender {
NSLog(@"TextfieldURL ist: %@", _textFieldUrl);
NSError *error = nil;
NSString* userAgent = @"Desktop";
NSHTTPURLResponse *response = nil;
NSInteger statusCode = [response statusCode];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:_textFieldUrl cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30.0];
[request addValue:userAgent forHTTPHeaderField:@"User-Agent"];
//NSData *conn = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSData* conn = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
[self connection:conn didReceiveResponse:response];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSInteger statusCode = [httpResponse statusCode];
NSDictionary* headers = [httpResponse allHeaderFields];
NSLog(@"\n \n DELEGATE STATUS -->: \n \n %d \n \n HEADERS -->: \n \n \n %@", statusCode, headers);
}
これは、ポート 80 で実行されている私の Apache の出力例です。Wi-Fi 経由で実行
DELEGATE STATUS -->:
200
HEADERS -->:
{
"Accept-Ranges" = bytes;
Connection = "Keep-Alive";
"Content-Length" = 38;
"Content-Type" = "text/html";
Date = "Wed, 29 May 2013 13:42:34 GMT";
Etag = "\"b1fcde-26-4dc47bfd46880\"";
"Keep-Alive" = "timeout=5, max=80";
"Last-Modified" = "Thu, 09 May 2013 11:57:06 GMT";
Server = "Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1"; }
T-Mobile で 3g を介してそれを行った場合、ヘッダーに「Age = X」フィールドも追加します。問題は、ポート 80 でサービスをシャットダウンしても、そのアプリはまだオンラインであり、年齢がまだカウントされていることです。
Wifi 経由ですべてが完全に機能します。サイトがダウンしているとき、正しいステータス コードとエラー メッセージが表示されました。サイトが存在しない場合は、0 を取得しました。
これらの問題は、モバイル ネットワークでのみ発生します。
サイトから正しいステータスを取得するためにプロキシを渡すにはどうすればよいですか?