我想使用NDURL下載文件下載。爲此,我必須登錄到一個網站。 我這樣做使用NSMutableURLRequest
,我發送使用sendSynchronousRequest
NSURLConnection
我從該消息調用收到的數據確實是確認我成功登錄的html頁面。 要下載我用下面的代碼文件:登錄後(使用POST請求)下載文件(使用NSURLDownload)
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: @"http://www.domain.com/getfile.php?file=1"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// Create the connection with the request and start loading the data.
NSURLDownload *theDownload = [[NSURLDownload alloc] initWithRequest:theRequest
delegate:self];
if (theDownload) {
// Set the destination file.
NSLog(@"Starting Download...");
NSLog(@"%@", [theDownload description]);
[theDownload setDestination:destinationFilename allowOverwrite:YES];
pathToZipFile = destinationFilename;
} else {
NSLog(@"Download failed...");
return nil;
}
但我收到的數據是HTML頁面告訴我,我必須登錄才能下載文件。 關於這個的任何想法? NSURLDownload與NSURLConnection有不同的會話嗎? 在此先感謝!