2012-05-25 43 views
5

使用NSConnection連接到「www.google.com」時出現錯誤。使用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"; 
} 

回答

16

嘗試NSString *urkString = @"http://www.google.com";你需要有URL方案的每一個URL。即http://https://

+0

謝謝realy.it已由您提供的解決方案解決 – Jonathan

相關問題