问题
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