I have been stuck with this for a while and don't seem to get around this.
I am trying to read the contents of an URL as a string from an URL, But i get a weird
Error -> Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
My code :
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 ;
}
What am I doing wrong? I tried using getting as NSData as well, but I get null back.
See Question&Answers more detail:os