iPhone NSURL获取最后重定向的URL [英] iPhone NSURL get last redirected url

查看:120
本文介绍了iPhone NSURL获取最后重定向的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将您的NSURL更新为您的网址将使用NSURL或NSRequest重定向到
的最后一个网址

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.

推荐答案

zanque的解决方案有效,但为了避免下载无用数据,我会改变HEAD的http方法:

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;

这篇关于iPhone NSURL获取最后重定向的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆