Cookie request header on Windows.Networking.BackgroundTransfer.BackgroundDownloader not working

笑着哭i 提交于 2020-01-14 06:05:14

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/8381346/cookie-request-header-on-windows-networking-backgroundtransfer-backgrounddownloa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!