0

I want to get some information from this website "http://phim14.net/". I use this code :

NSURL *url = [NSURL URLWithString:@"http://phim14.net/"];
     NSError *error;
     NSData *htmlData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
     TFHpple *parser = [TFHpple hppleWithHTMLData:htmlData];

At the beginning this code is working and I can get some info. But after several times trying I met an error that "htmlData" was return nil, so I think the website was down but I can connect to that webpage using Firefox. I try to parse other website but it's still ok? I try to print out the error and it said that

`"error NSError *   domain: @"NSCocoaErrorDomain" - code: 256   0x00007fbb224023c0"`

Someone please help me figure out what is the problem??

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tommy
  • 302
  • 4
  • 15

2 Answers2

0

It seems errorcode 256 doesn't have much description. So for safe way to get data from URL, use this method sendSynchronousRequest:returningResponse:error: from NSURLConnection.

NSData* data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30] returningResponse:nil error:&error];

Also please check these answer1, answer2

Community
  • 1
  • 1
arthankamal
  • 6,341
  • 4
  • 36
  • 51
-1

Your URL is missing the scheme: "http://" and this is giving you the error:

Error -> Error Domain=NSCocoaErrorDomain Code=256

Try adding this to the URL and it should work.

Dharma
  • 3,007
  • 3
  • 23
  • 38
mgm
  • 1,298
  • 14
  • 16