How to get Redirected URL
html, ios, iphone, objective-c, xcode
Solution
1) Specify that your class conforms to the UIWebViewDelegate protocol (and make sure your WebView's delegate outlet is connected to your view controller):
@interface YourWebsiteViewController : UIViewController <UIWebViewDelegate>
2) Add the following delegate method:
-(void)webViewDidStartLoad:(UIWebView *)webView
{
NSURL *url = [webView.request mainDocumentURL];
NSLog(@"The Redirected URL is: %@", url);
}
Depending on what you're trying to do with this information, you might want to substitute #2 for this method (which will allow you the opportunity to prevent a page from loading):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request mainDocumentURL];
NSLog(@"The Redirected URL is: %@", url);
// Return YES if you want to load the page, and NO if you don't.
return NO;
}
Problem
I have a URL.when i try to open it in browser, it will redirect to another URL & display the Content. I want that content But i don't get that redirected URL. So, I can't able to display data. How can i do that programmatically?? e.g. URL which i have : http://www.windpowerengineering.com/?p=11020 & the redirected URL is: http://www.windpowerengineering.com/design/mechanical/blades/bladeless-turbine-converts-wind-into-fluid-power/ I want this redirected URL. How can i get this?