Asihttprequests not working

I am trying to load a file queue using ASIHTTPRequest. Each request constantly fails. I know the URLs are correct, I traced them and pulled them into the browser, and there are files. I have few 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 do not know how to fix it. If I change the request URL to something simple, like http: //mysite/content/track.mp3 , everything works fine. But when I use the source url, the request fails. The original url is as follows:

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

I think this might have something to do with spaces, but I thought nsurl would handle this stuff?

+4
source share
1 answer

It turns out NSURL will not safely encode the url string for you. In my cases, these are spaces in the URL where the problem occurs. Spirituality was next.

NSString *safestring=[unsafestring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;

+4
source

Source: https://habr.com/ru/post/1341833/


All Articles