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 foll
Sometimes Cookies are not set even after you assign all http headers. it is better to create mutable request and copy your nsurlrequest and add your custom header to it so that all information from original request is retained in mutable one.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
if(check if key not present){
NSMutableURLRequest *re = [[NSMutableURLRequest alloc] init];//alloc init not required
re = (NSMutableURLRequest *) request.mutableCopy;
[re setValue:@"Your Custom Value" forHTTPHeaderField:@"Yout Custom Header"];
[webView loadRequest:re] ;
return NO;
}
return YES;
}