0

I want to get HTML from website. I wrote below code but this returns (null).

NSString *strURL = @"http://www.googole.com";

- (NSString *)getHtml
{
    NSURL *url = [NSURL URLWithString: strURL];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest : req
                                         returningResponse : &response
                                                     error : &error];
    NSString *strData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    return strData;
}
Martin G
  • 17,357
  • 9
  • 82
  • 98
Feel Physics
  • 2,783
  • 4
  • 25
  • 38

1 Answers1

2

I think you have mistyped the url. It should be NSString *strURL = @"http://www.google.com";

Adam
  • 26,549
  • 8
  • 62
  • 79
iPhoneDv
  • 1,969
  • 1
  • 19
  • 34