views:

153

answers:

2

Hello Guys,

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.

+1  A: 

You'll only be able to find this out after trying to connect using NSURLConnection. If you add a method to your NSURLConnection delegate, -connection:willSendRequest:redirectResponse:, you'll be notified before redirects happen. Just grab the URL from the passed request, and that's your answer.

Ben Gottlieb
i wanna do it synchronously.. can it be done ?
zanque
I don't believe so. Apple discourages synchronous operations.
Ben Gottlieb
+2  A: 

i did it,

here is how

NSURL *originalUrl=[NSURL URLWithString:@"http://YourURL.com"];
NSData *data=nil;  
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:originalUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
NSURLResponse *response;
NSError *error;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSURL *LastURL=[response URL];
[request release];
[error release];
zanque