I searched/googled a lot but could not get the answer on how to capture HTTP response headers in UIWebview
. Say I redirect to user to registration gateway(which is already active) in UIWebview on App Launch and when user finishes the registration, the app should be notified with the successful unique id assigned to the user on registration which is passed back in HTTP Response Headers.
Is there any direct way to capture/print the HTTP Response headers using UIWebview
?
There is no way to get the response object from the UIWebView
(file a bug with apple for that, id say)
1) via the shared NSURLCache
- (void)viewDidAppear:(BOOL)animated {
NSURL *u = [NSURL URLWithString:@"http://www.google.de"];
NSURLRequest *r = [NSURLRequest requestWithURL:u];
[self.webView loadRequest:r];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSCachedURLResponse *resp = [[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request];
NSLog(@"%@",[(NSHTTPURLResponse*)resp.response allHeaderFields]);
}
@end
if this works for you this is ideal
ELSE
UIWebView
:) that'd be a bad workaround for this! (as Richard pointed out in the comments.) It DOES have major drawbacks and you have to see if it is a valid solution in your case
NSURL *u = [NSURL URLWithString:@"http://www.google.de"];
NSURLRequest *r = [NSURLRequest requestWithURL:u];
[NSURLConnection sendAsynchronousRequest:r queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *resp, NSData *d, NSError *e) {
[self.webView loadData:d MIMEType:nil textEncodingName:nil baseURL:u];
NSLog(@"%@", [(NSHTTPURLResponse*)resp allHeaderFields]);
}];