iPhone NSURL get last redirected url

前端 未结 4 1074
轮回少年
轮回少年 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:14

    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;
    

提交回复
热议问题