1

我无法使用以下代码下载文件。服务器需要之前检索到的 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);
    });
4

1 回答 1

2

我有同样的问题,我在msdn上问它。这是一个答案,但它仍然对我不起作用,您可以尝试以下代码

//twice calling SetRequestHeader
var downloader = new BackgroundDownloader();
downloader.SetRequestHeader("Cookie", "any non-empty string here");
downloader.SetRequestHeader("Cookie", "cookie1=something");

请参阅http://support.microsoft.com/kb/234486/en了解详细的解决方法,尽管它针对旧的 XMLHttpRequest 类。

于 2012-01-17T02:39:15.387 回答