My iOS UIWebView page is based on Cordova open source framework, and I want to add some customize http headers in its webview URL request, my solution is to add them in the following UIWebView delegate method.
Debug shows that headers are added successfully, but in fact the request doesn't bring them out. Using Wireshark to capture network packets and found only standard headers are available, no my customize ones.
My testing is based on simulator (iOS 7.1), anyone who has experience on this topic please share and discuss together, thanks in advance.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// Add customize http headers in UIWebView request
if([request isKindOfClass:[NSMutableURLRequest class]]) {
NSMutableURLRequest * mRequest = (NSMutableURLRequest *)request;
[mRequest setValue:@"1.1" forHTTPHeaderField:@"appVersion"];
[mRequest setValue:@"iPhone 4S" forHTTPHeaderField:@"deviceModel"];
}
return [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}