我正在向我的 WebApi 控制器发送多部分表单数据。我感兴趣的内容包括图像和另一个非图像值。我可以读取图像没问题,但无法弄清楚如何读取用户名部分(以andy作为值)。它不在提供程序的 FormData 属性中。我怎么才能得到它?
多部分表单数据
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Filename"
image.jpg
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="username"
andy
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Filedata"; filename="image.jpg"
Content-Type: application/octet-stream
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Upload"
Submit Query
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0--
控制器代码
string root = System.Web.HttpContext.Current.Server.MapPath("~/App_Data");
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(root);
var task = request.Content.ReadAsMultipartAsync(provider).ContinueWith<HttpResponseMessage>(o =>
{
...
}