我无法使用以下代码下载文件。服务器需要之前检索到的 cookie 来下载文件。
在 Fiddler2 中观察时,发送到服务器的请求标头缺少设置的 cookie。
饼干不粘在上面有什么原因backgrounddownloader
吗?设置任何其他标题,如User-Agent
, 等,此处未显示,但工作正常。
Windows.Storage.ApplicationData.current.temporaryFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.replaceExisting).then(function (newFile)
{
var uri = Windows.Foundation.Uri(uriString);
var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
downloader.setRequestHeader("Cookie", cookie);
// Start the download asynchronously.
var promise = downloader.startDownloadAsync(uri, newFile);
// Persist the download operation.
operation = promise.operation;
// Assign callbacks associated with the download.
promise.then(completeCallback, error);
});