asihttp请求失败
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明 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]
;