我有 WEbAPI2 后端。
我尝试从 postman 发送表单数据
但是得到这个错误
"No MediaTypeFormatter is available to read an object of type 'StartWorkingDay' from content with media type 'multipart/form-data'.",
这是我的 Controller 代码
// POST: api/StartWorkingDays
[ResponseType(typeof(StartWorkingDay))]
public IHttpActionResult PostStartWorkingDay(StartWorkingDay startWorkingDay)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.StartWorkingDays.Add(startWorkingDay);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = startWorkingDay.Id }, startWorkingDay);
}
当我通过原始数据发送时,一切正常
如何让它接收multipart/form-data
?
最佳答案
取自MSDN
application/x-www-form-urlencoded
Form data is encoded as name/value pairs, similar to a URI query string. This is the default format for POST.
多部分/表单数据
Form data is encoded as a multipart MIME message. Use this format if you are uploading a file to the server.
在 postman 中使用 enctype x-www-form-urlencoded,而不是 form-data
关于c# - 此资源不支持“multipart/form-data”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45072864/