Windows.Networking.BackgroundTransfer.BackgroundDownloader上的Cookie请求标头不起作用 [英] Cookie request header on Windows.Networking.BackgroundTransfer.BackgroundDownloader not working

查看:63
本文介绍了Windows.Networking.BackgroundTransfer.BackgroundDownloader上的Cookie请求标头不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用以下代码下载文件.服务器需要较早检索到的cookie以下载文件.

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

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

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

是否有任何原因导致cookie不粘在backgrounddownloader上?设置其他任何标头,例如User-Agent等,此处未显示,但可以正常工作.

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

推荐答案

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

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

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

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

这篇关于Windows.Networking.BackgroundTransfer.BackgroundDownloader上的Cookie请求标头不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆