2012-10-05 46 views
0

我想從網站獲取HTML。我寫下面的代碼,但是這返回(null)NSURLConnection(Syncronous Request)返回(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; 
} 
+0

如果你看着你的錯誤 - 你就會知道問題是什麼 - 這就是它的目的。 – rdelmar

回答

2

我想你錯了輸入的網址。 它應該是NSString *strURL = @"http://www.google.com";