Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I got an error when connect to 'www.google.com' use NSConnection

Tags:

nsconnection

I get an error when connecting to 'www.google.com' using NSConnection.

I cannot find the reason why. Any help will be appreciated.

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];
}

But it called this method. The error is:

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";
}
like image 429
Jonathan Avatar asked May 25 '12 06:05

Jonathan


1 Answers

try NSString *urkString = @"http://www.google.com"; You need to have URL Scheme to every URL. i.e. http:// or https://

like image 192
Himanshu A Jadav Avatar answered Sep 19 '22 16:09

Himanshu A Jadav