下面是問題,我使用AFNetwoking獲取頁面html返回。 我可以看到responseObject是一個html頁面。 這是我使用的代碼。如何從html代碼加載頁面
NSURL *url = [NSURL URLWithString:@"https://graph.z.qq.com/moc2/authorize"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setValue:@"code" forKey:@"response_type"];
[params setValue:@"100266567" forKey:@"client_id"];
[params setValue:@"http://www.qq.com" forKey:@"redirect_uri"];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:@"https://graph.z.qq.com/moc2/authorize" parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
__block NSData * data = [[NSData alloc] init];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
data = responseObject;
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]) ;
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Error: %@", error);
}];
[operation start];
現在我想將響應對象加載到uiwebview中。 我試過loadHTMLString,但沒有奏效。
[webView loadHTMLString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] baseURL:url ];
有沒有人有這方面的想法?
是的,你說得對,我使用AFNetworking獲取返回數據。回報數據就是我想要的。但現在問題是返回數據只是一個NSData類型的對象。我不知道如何使用它,以uiwebview或其他方式顯示它。 – zedzhao