//此方法每次進行網(wǎng)絡(luò)請求的時候烹吵,都會調(diào)用
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *urlString = [[request URL] absoluteString];
#if DEBUG
NSLog(@"==> %@",urlString);
#endif
NSMutableURLRequest *mutableRequest = [request mutableCopy];
NSDictionary *requestHeaders = request.allHTTPHeaderFields;
// 判斷請求頭是否已包含小槐,如果不判斷該字段會導(dǎo)致webview加載時死循環(huán)
if (requestHeaders[@"usertoken"]) {
return YES;
} else {
[mutableRequest setValue:value forHTTPHeaderField:@"usertoken"];
request = [mutableRequest copy];
[webView loadRequest:request];
return NO;
}
return YES;
}