Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone NSURL get last redirected url

i wonder how can you update your NSURL to the last url that a your url will redirect to
using NSURL or NSRequest

appreciate your help. thanks.

like image 818
Mina Mikhael Avatar asked Dec 23 '09 11:12

Mina Mikhael


1 Answers

zanque's solution works, but in order to avoid downloading "useless" data, I'd change the http method to HEAD :

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:orinigalURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0];
[request setHTTPMethod:@"HEAD"];
NSURLResponse *response = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSURL *finalURL = response.URL;
like image 116
nstefan Avatar answered Oct 04 '22 11:10

nstefan