【问题标题】:I got an error when connect to 'www.google.com' use NSConnection使用 NSConnection 连接到“www.google.com”时出现错误
【发布时间】:2012-05-31 18:10:12
【问题描述】:

使用NSConnection 连接到“www.google.com”时出现错误。

我找不到原因。任何帮助将不胜感激。

NSString *urkString = @"www.google.com";
NSURL *url = [NSURL URLWithString:urkString];

NSURLRequest *request = [NSURLRequest requestWithURL:url
                                          cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];

_connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];  
if(_connection)
{
    _receivedData = [[NSMutableData alloc] init];
}
else
{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Cannot connect to the Web site." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];

    [alertView show];
    [alertView release];
}

但是它调用了这个方法。错误是:

Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0x4c9feb0 {NSErrorFailingURLStringKey=www.google.com, NSErrorFailingURLKey=www.google.com, NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x4c9fdf0 "unsupported URL"}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    _endSystemDate = [self getSystemDate];
    _receivedData = nil;
    _connection = nil;
    _status = @"Completed";
}

【问题讨论】:

    标签: nsconnection


    【解决方案1】:

    试试NSString *urkString = @"http://www.google.com"; 你需要为每个 URL 设置 URL Scheme。即http://https://

    【讨论】:

    • 感谢您的解决。您提供的解决方案已解决
    猜你喜欢
    • 2020-04-04
    • 1970-01-01
    • 2020-08-22
    • 2019-06-21
    • 2016-07-21
    • 2011-05-05
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    相关资源
    最近更新 更多