下面是问题,我使用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 ];
有没有人有这方面的想法?
2013-07-28
zedzhao