0

这是问题,我使用 AFNetwoking 获取返回的页面 html。我可以看到 responseObject 是一个 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];

现在我想将 responseObject 加载到 uiwebview 中。我尝试了 loadHTMLString ,但没有用。

[webView loadHTMLString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] baseURL:url ];

有人对此有任何想法吗?

4

2 回答 2

0

尝试覆盖此方法,并返回 YES:

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}

请记住将您的类设置为 UIWebViewDelegate 并将您的 UIWebView 的.delegate属性链接到self.

于 2013-07-28T09:15:45.047 回答
0

看起来您没有在任何处理程序块中加载数据。

AFNetworking 是异步的。因此,如果您在返回任何数据之前尝试加载数据,则不会发生任何事情。

将加载代码放在您记录数据的同一位置。

于 2013-07-28T08:50:11.693 回答