【问题标题】:Cookie request header on Windows.Networking.BackgroundTransfer.BackgroundDownloader not workingWindows.Networking.BackgroundTransfer.BackgroundDownloader 上的 Cookie 请求标头不起作用
【发布时间】:2011-12-05 05:26:57
【问题描述】:

我无法使用以下代码下载文件。服务器需要之前检索到的 cookie 来下载文件。

在 Fiddler2 中观察到,发送到服务器的请求标头缺少设置的 cookie。

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);
    });

【问题讨论】:

    标签: javascript windows microsoft-metro


    【解决方案1】:

    我有同样的问题,我在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 类。

    【讨论】:

      猜你喜欢
      • 2020-10-27
      • 2013-09-18
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多