0
当我从JSON格式的请求主体传递参数,然后没有来到网页api。我的代码:如何通过Web API使用Content-Type请求身体参数:multipart/form-data?
public async Task<HttpResponseMessage> Upload([FromBody]AddPhotoBizPrm addPhotoBizPrm)
{
json_obj.RESPONSE = new { };
string images = "";
if (Request.Content.IsMimeMultipartContent())
{
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var file in provider.Contents)
{
var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
var buffer = file.ReadAsByteArrayAsync();
images += filename;
//Do whatever you want with filename and its binary data.
}
}
json_obj.RESPONSE = images;
json_obj.MESSAGE = "";
json_obj.STATUS_CODE = 701;
return new HttpResponseMessage()
{
Content = new StringContent("ok")
};
}
,我从请求体传递参数:
{
deviceid:"",
rate:2,
review:"",
skuid:123,
userId:875904
}
我想使用方法类型POST –
访问文件和请求参数请编辑时使用预览窗口,因此您可以检查您的代码是否已正确格式化。谢谢。 – halfer