我想在 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' 标头中设置的边界匹配。
我的代码有什么问题/缺少什么?