短縮URLから音声ファイルをダウンロードしたい( のようなwww.adjix.com
) 通常のリンクからやってみるとOKなのですが、短縮URLからだとリダイレクトしてからダウンロードする方法
コードのこの部分を使用してリクエストを作成します。
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";