Windows.Networking.BackgroundTransfer.BackgroundDownloader 上的 Cookie 请求标头不起作用
我无法使用以下代码下载文件。服务器需要之前检索到的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题,我在msdn上问的。这是一个答案,但对我来说仍然不起作用,您可以尝试以下代码
请参阅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
Please refer to http://support.microsoft.com/kb/234486/en for detailed workaround although it's against old XMLHttpRequest class.