0
我尝试从我的服务器上下载文件,这是代码,在我的控制台上我看到xml文件,但无法保存。 你的问题在哪里?ASIHTTPRequest - 下载问题
- (IBAction)grabURL:(id)sender{
NSURL *url = [NSURL URLWithString:@"http://www.endurodoc.net/photo/data.xml"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
NSLog(@"%@",response);
}
else{
NSLog(@"Errore");
}
//[request setDownloadDestinationPath:@"/Users/kikko/Desktop/data.xml"];
// SAVED PDF PATH
// Get the Document directory
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your saved pdf location
NSString *pdfLocation = [documentDirectory stringByAppendingPathComponent:@"data.xml"];
// TEMPORARY PDF PATH
// Get the Caches directory
NSString *cachesDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your temp pdf location
NSString *tempPdfLocation = [cachesDirectory stringByAppendingPathComponent:@"data.xml"];
// Tell ASIHTTPRequest where to save things:
[request setTemporaryFileDownloadPath:tempPdfLocation];
[request setDownloadDestinationPath:pdfLocation];
}
如果NSURLConnection完全可以在不使用任何第三方代码的情况下使用ASIHTTPRequest,您为什么要使用ASIHTTPRequest? – bioffe