2015-07-22 56 views
0

我正在實現一個Windows Phone 8.1應用程序,該應用程序創建BackgroundDownloaders以將雲文件還原到手機。將POST數據附加到BackgroundDownloader

雲需要將文件ID作爲附加的JSON POST請求發佈,我無法找到一種方法來定義它的BackgroundDownloader對象。

任何想法?

回答

0

要做到這一點的方法是創建一個臨時文件來保存JSON發佈數據並將其發送到CreateDownload函數(作爲最後一個StorageFile參數)。另外,我添加了一個Content-Type頭來描述它(對於我來說它是application/x-www-form-urlencoded)並將它添加到SetRequestHeader中。

//set the Content-Type header 

BackgroundDownloader^ downloader = ref new BackgroundDownloader(); 
Platform::String^ SKey2 = ref new Platform::String(L"Content-Type"); 
Platform::String^ SValue2 = ref new Platform::String(L"application/x-www-form-urlencoded"); 
downloader->SetRequestHeader(SKey2, SValue2); 

//Create a temporary file and write the POST data into it 

StorageFile^ postDataFile = nullptr; 
.... 

//Call CreateDownload with the postDataFile 
downloader->CreateDownload(uri, file, postDataFile); 

這對我有效。