【发布时间】:2014-10-11 18:54:59
【问题描述】:
我想在 windows 8.1 中通过 BackgroundUploader 使用 Multipart/related Content-Type 上传文件
我的代码如下
BackgroundUploader uploader = new BackgroundUploader();
uploader.SetRequestHeader("Content-Type", "multipart/related; boundary=foo_bar_baz");
uploader.Method = "POST";
// Create upload content
List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();
// File metadata
var part = new BackgroundTransferContentPart();
part.SetHeader("Content-Type", "text/plain");
part.SetText(file.DisplayName);
parts.Add(part);
// File
// Here file is of type StorageFile
part = new BackgroundTransferContentPart();
part.SetHeader("Content-Type", file.ContentType);
part.SetFile(file);
parts.Add(part);
UploadOperation upload = await uploader.CreateUploadAsync(new Uri("upload_url",UriKind.Absolute), parts);
await upload.StartAsync().AsTask(cts.token); // cts is CancellationTokenSource
但是,当我运行此代码时,我得到一个异常提示
WinRT 信息:'boundary':如果设置了 'Content-Type' 标头, 边界不能为空,并且必须与 'Content-Type' 标头。
我的代码有什么问题/缺少什么?
【问题讨论】:
标签: windows-runtime windows-8.1 windows-phone-8.1 multipart background-transfer