2009-02-07 90 views
0

我想從一個簡短的網址下載一個聲音文件(如: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; 

當我嘗試下載文件用短URL(adjix.com/3na3),標題是:

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

回答

0

你能否提供更多信息?特別是,最好提及您用來執行HTTP請求的類,以及在使用重定向的URL時會發生什麼情況。

0

NSURLConnection有一個委託方法,您可以專門處理重定向。但是,可能是因爲您的請求的用戶代理字符串,所連接的服務器的行爲不同。