I am trying to make a simple GET request using NSURLConnection in NSURLConnection 6 (Beta7 2) in the iOS 8 SDK, which does not work with "Code 1005, network connection was lost." The call fails when I try to retrieve http://www.google.com or several other sample pages from the Internet, but succeeds if I make a request to a simple HTTP server on localhost ( python -m SimpleHTTPServer ). I also tried using the AFNetworking library (2.4.1) - URLs that do not match NSURLConnection also fail with the library.
Here is my code -
NSString * url = @"http://0.0.0.0:8000"; // NSString * url = @"http://www.google.com"; NSLog(@"URL : %@", url); // Mutable is probably not required, but just in case it REALLY WANTS me to set HTTP method NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; [theRequest setHTTPMethod:@"GET"]; NSURLResponse *urlResponse = nil; NSError *error = nil; NSData * data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error]; if (error == nil) { NSString *response = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSLog(response); } else { NSString *response = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSLog(@"%@", [error userInfo]); }
Logs:
2014-09-11 17:34:23.950 SearchExample[5092:2074687] URL : http://www.google.com 2014-09-11 17:34:24.023 SearchExample[5092:2074687] { NSErrorFailingURLKey = "http://www.google.com"; NSErrorFailingURLStringKey = "http://www.google.com"; NSLocalizedDescription = "The network connection was lost."; NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1005 \"The network connection was lost.\" UserInfo=0x7fc8515640a0 {NSErrorFailingURLStringKey=http://www.google.com/, NSErrorFailingURLKey=http://www.google.com/, _kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1, NSLocalizedDescription=The network connection was lost.}"; "_kCFStreamErrorCodeKey" = 57; "_kCFStreamErrorDomainKey" = 1; } 2014-09-11 17:34:24.023 SearchExample[5092:2074687] URLResponse: (null)
ios cocoa-touch
Vikesh Sep 11 '14 at 21:35 2014-09-11 21:35
source share