2015-07-22 63 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); 

这对我有效。