2011-07-05 15 views
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]; 

} 
+0

NSURLConnectionがサードパーティーのコードを使用せずに正確に行うことができる場合、なぜASIHTTPRequestを使用しますか? – bioffe

答えて

3

:ASIHTTPRequestは、要求が行われたときに保存したファイルを実行し

[request startSynchronous]; 

ので、あなたは、これらのプロパティを設定した場合、要求はすでに持っていた後:前

[request setTemporaryFileDownloadPath:tempPdfLocation];  
[request setDownloadDestinationPath:pdfLocation]; 

を何も起こりませんでした。

+0

ありがとう! – kikko088

関連する問題