asihttprequests failing
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]开发者_如何学Python];
//[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?
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]
;
精彩评论