ios http-request with provider proxy - site始终在线

时间:2013-05-29 13:49:57

标签: ios objective-c httprequest

我有一段代码,它返回网站的标题信息。如果我关闭端口80上的服务并且网站处于脱机状态,则应用程序仍然会向我返回标头信息。这是由于某些提供商的代理。 前三次它正常工作。它响应在线或offine。在请求之后,该网站不断在线申请该应用程序。

这是我的代码:

- (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);
}

这是我的apache在端口80上运行的示例输出。通过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。

我只在移动网络上遇到这些问题。

如何通过代理从站点获取正确的状态?

0 个答案:

没有答案