我在Android应用程序上使用webview。
我想在webview加载时从响应请求中获取标题和正文(POST
参数)信息。
在我的iOS应用程序中,我已经使用此代码获取它们:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *username = [self queryDictionary:request][@"username"];
if (username) {
self.userid = username;
}
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSCachedURLResponse *resp = [[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request];
NSString *status = [(NSHTTPURLResponse *)resp.response allHeaderFields][@"Authentication"];
if ([status isEqualToString:@"OK"] && ![self.userid isEqualToString:@""]) {
// TODO: 서버 API 필요
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"send to server with user id (%@), token %@ ", self.userid, appDelegate.registrationToken);
} else if ([status isEqualToString:@"failuer"]) {
self.userid = @"";
}
}
如何在Android上实现相同的结果?