iPhone NSURL get last redirected url

前端 未结 4 1101
轮回少年
轮回少年 2021-01-01 03:01

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.

4条回答
  •  [愿得一人]
    2021-01-01 03:24

    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];
    

提交回复
热议问题