写一个类继承NSURLProtocol,在 + (BOOL)canInitWithRequest:(NSURLRequest *)request 方法拦截request为request添加请求头,这样所有的webview操作请求都会调到这里,为request添加请求头,而且不影响webview的goBack方法返回
+ (void)load {
[NSURLProtocol registerClass:self];
}
+ (BOOL)canInitWithRequest:(NSURLRequest *)request {
if ([request isKindOfClass:[NSMutableURLRequest class]]) {
[(id)request setValue:@"iOS" forHTTPHeaderField:@"Authorization"];
}
return NO;
}