iphone – asihttprequests失败

我正在尝试使用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];

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...