Cocoa touch 从短URL下载文件

Cocoa touch 从短URL下载文件,cocoa-touch,short-url,Cocoa Touch,Short Url,我想从短URL下载声音文件(如:www.adjix.com) 当我尝试从正常的链接,这是确定的,但从短网址,如何首先重定向,然后下载 我使用这部分代码创建请求: NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlToSound]]; NSURLConnection *theConnection =[[NSURLConnection alloc] initWi

我想从短URL下载声音文件(如:
www.adjix.com
) 当我尝试从正常的链接,这是确定的,但从短网址,如何首先重定向,然后下载

我使用这部分代码创建请求:

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlToSound]];

NSURLConnection *theConnection =[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if (theConnection) {
    self.receiveData = [[NSMutableData data] retain];
}
此代码用于查看标题:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    [receiveData setLength:0];

    if ([response isKindOfClass:[NSHTTPURLResponse self]]  ) {
        NSDictionary *headers = [(NSHTTPURLResponse *)response allHeaderFields];
        NSLog(@"headers: %@", headers);
   }
}
当我尝试直接下载时,指向MP3标题的链接是:

    "Accept-Ranges" = bytes;
    Connection = "Keep-Alive";
    "Content-Length" = 21316;
    "Content-Type" = "audio/mpeg";
    Date = "Sat, 07 Feb 2009 16:01:34 GMT";
    Etag = "\"2d810-5344-7dda240\"";
    "Keep-Alive" = "timeout=15, max=100";
    "Last-Modified" = "Sat, 25 Jun 2005 12:26:41 GMT";
    Server = Apache;
    "Cache-Control" = "max-age=60";
    Connection = close;
    "Content-Length" = 692;
    "Content-Type" = "text/html";
    Date = "Sat, 07 Feb 2009 19:18:23 GMT";
    Expires = "Sat, 07 Feb 2009 19:19:23 GMT";
    Server = "Apache/1.3.41 (Darwin) mod_ssl/2.8.31 OpenSSL/0.9.7l";
当我尝试下载带有短URL(
adjix.com/3na3
)的文件时,标题是:

    "Accept-Ranges" = bytes;
    Connection = "Keep-Alive";
    "Content-Length" = 21316;
    "Content-Type" = "audio/mpeg";
    Date = "Sat, 07 Feb 2009 16:01:34 GMT";
    Etag = "\"2d810-5344-7dda240\"";
    "Keep-Alive" = "timeout=15, max=100";
    "Last-Modified" = "Sat, 25 Jun 2005 12:26:41 GMT";
    Server = Apache;
    "Cache-Control" = "max-age=60";
    Connection = close;
    "Content-Length" = 692;
    "Content-Type" = "text/html";
    Date = "Sat, 07 Feb 2009 19:18:23 GMT";
    Expires = "Sat, 07 Feb 2009 19:19:23 GMT";
    Server = "Apache/1.3.41 (Darwin) mod_ssl/2.8.31 OpenSSL/0.9.7l";

你能提供更多的信息吗?特别是,最好提及用于执行HTTP请求的类,以及使用重定向URL时中断的内容。

您可能需要尝试GTMHTTPFetcher类,它是HTTP请求的一部分。它为您处理重定向。

NSURLConnection有一个委托方法,您可以专门实现该方法来处理重定向。但是,由于请求的用户代理字符串,您连接到的服务器的行为可能有所不同