0

我想从网站获取 HTML。我写了下面的代码,但这会返回(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;
}
4

1 回答 1

2

我认为您输入了错误的网址。它应该是NSString *strURL = @"http://www.google.com";

于 2012-10-05T04:31:38.687 回答