首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我在使用NSConnection连接到'www.google.com‘时出错

我在使用NSConnection连接到'www.google.com‘时出错
EN

Stack Overflow用户
提问于 2012-05-25 14:42:06
回答 1查看 4.3K关注 0票数 5

当使用NSConnection连接到'www.google.com‘时,我得到一个错误。

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

代码语言:javascript
复制
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"}

代码语言:javascript
复制
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    _endSystemDate = [self getSystemDate];
    _receivedData = nil;
    _connection = nil;
    _status = @"Completed";
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-25 14:50:39

尝试NSString *urkString = @"http://www.google.com";你需要有网址方案到每个网址。即http://https://

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10749687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档