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