Windows.Networking.BackgroundTransfer.BackgroundDownloader 上的 Cookie 请求标头不起作用

发布于 2024-12-19 07:41:23 字数 918 浏览 4 评论 0原文

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

I am unable to download file with the following code. The server requires the cookie that is retrieved earlier for downloading the file.

The request headers that are being sent to server are missing the cookie that is set, when observed in Fiddler2.

Is there any reason why the cookie is not sticking to the backgrounddownloader? Setting any other header like User-Agent, etc not shown here but works fine.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-12-26 07:41:23

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

I have the same problem and I ask it on msdn. this is one answer, but it's still not work for me, You can try the following code

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

Please refer to http://support.microsoft.com/kb/234486/en for detailed workaround although it's against old XMLHttpRequest class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文