asihttp请求失败

发布于 2024-10-20 07:21:25 字数 1636 浏览 0 评论 0原文

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


}

编辑

我想我发现了问题,但我不知道如何解决它。如果我将请求网址更改为简单的内容,例如 http://mysite/content/track.mp3 这一切工作正常。但是当我使用原始 url 时,请求失败。原始网址如下所示

http://site-media.s3.amazonaws.com/2020 Vision - Deep Tech House 和 Techno/P_122_DrumLp6.mp3

我认为这可能与空间有关,但我认为 nsurl 会处理这些东西?

I'm trying to download a a queue of files using ASIHTTPRequest. Each request is permanently failing. I know that the urls are valid, I've traced them out and popped them into a browser and the files are there. I've not much ideas on how to debug this.

-(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];


}

EDIT

I think I found the problem but I dont know how to fix it. If I change the request url to something simple like http://mysite/content/track.mp3 it all works fine. But when I use the original url the request fails. The original url looks like this

http://site-media.s3.amazonaws.com/2020 Vision - Deep Tech House and Techno/P_122_DrumLp6.mp3

I think it might have something to do with the spaces but I thought nsurl would handle that stuff?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一口甜 2024-10-27 07:21:25

事实证明 NSURL 不会为您安全地编码 url 字符串。在我的情况下,网址中的空格导致了问题。解决方案如下

NSString *safestring=[unsafestring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

It turns out that NSURL won't safely encode a url string for you. In my cases the spaces in the url where causing the problem. The soulution was as follows

NSString *safestring=[unsafestring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文