我已经坚持了一段时间,似乎并没有解决这个问题.
我试图从URL读取URL的内容作为字符串,但我得到一个奇怪的
错误 - >错误域= NSCocoaErrorDomain代码= 256"操作无法完成.(Cocoa错误256.)"
我的代码:
fetchedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"www.example.com/iphone"] encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@",fetchedString);
// if there is something wrong with the URL
if (error) {
NSLog(@"Error -> %@", error);
return ;
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我尝试使用获取作为NSData,但我得到null.