我有以下代码。
NSURL *serverUrl = [NSURL URLWithString:@"http://google.com"];
NSError *error = nil;
NSString *stringFromStream = [NSString stringWithContentsOfURL:serverUrl encoding:NSUTF8StringEncoding error:&error];
NSLog(@"string is %@ error is %@", stringFromStream, error);
这段代码产生以下错误
2012-05-29 11:57:46.914 [2221:f803] string is (null) error is Error Domain=NSCocoaErrorDomain Code=261 "The operation couldn’t be completed. (Cocoa error 261.)" UserInfo=0x6a36c60 {NSURL=http://google.com, NSStringEncoding=4}
但是如果我将 URL 更改为
NSURL *serverUrl = [NSURL URLWithString:@"http://apple.com"];
我会完美地工作。