当我以JSON格式从Request body传递参数时,不会遇到web api。我的代码:
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
}
答案 0 :(得分:0)
解决了这个问题。 我使用的是content-type = multipart / form-data,因此我们无法将json参数传递给请求体。 所以我们将像数据一样传递参数 设备ID =&#34;&#34;&安培;率= 2及复习=&#34;&#34;&安培; skuid = 123&安培;用户id = 875904