我正在尝试使用ASIHTTPRequest下载一个文件队列.每个请求都会永久失败.我知道网址是有效的,我已将它们追踪出来并将它们弹出到浏览器中,文件就在那里.我对如何调试这个没什么想法.
-(void) getRemoteFiles:(NSMutableArray *) M { [self createFileToAppDirectory]; if (!networkqueue) { networkqueue:[[[ASINetworkQueue alloc] init] autorelease]; } [[self networkQueue] cancelAllOperations]; [self setNetworkQueue:[ASINetworkQueue queue]]; [[self networkQueue] setDelegate:self]; [[self networkQueue] setRequestDidFinishSelector:@selector(requestFinished:)]; [[self networkQueue] setRequestDidFailSelector:@selector(requestFailed:)]; [[self networkQueue] setQueueDidFinishSelector:@selector(queueFinished:)]; int i; for (i=0; i<[M count]; i++) { NSString *url=[M objectAtIndex:i]; NSString* theFileName = [url lastPathComponent]; if ([theFileName isEqualToString:@"nothing"]==NO) { ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]]; //[request setDownloadDestinationPath:[self getDirectoryPathForFileName:theFileName]]; [[self networkQueue] addOperation:request]; } } [[self networkQueue] go]; }
编辑
我想我发现了问题,但我不知道如何解决它.如果我将请求URL更改为像http://mysite/content/track.mp3这样简单的东西,那么一切正常.但是当我使用原始URL时,请求失败.原始网址看起来像这样
http://site-media.s3.amazonaws.com/2020愿景 – Deep Tech House和Techno / P_122_DrumLp6.mp3
我认为它可能与空间有关,但我认为nsurl会处理那些东西?
解决方法
事实证明,NSURL不会为您安全地编码url字符串.在我的情况下,url中的空格导致问题.洗脱如下
NSString * safestring = [unsafestring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];