我试图做一个POST服务,返回一个列表Tienda
。我的代码看起来像这样:如何设置POST方法的webapi控制器
[HttpPost]
[ResponseType(typeof(List<TiendaWrapper>))]
public IHttpActionResult GetTiendasPost([FromBody]Tienda t)
{
List<Tienda> ListaTiendas = db.Tiendas.ToList();
List<TiendaWrapper> lstTiendas = new List<TiendaWrapper>();
foreach(Tienda T in ListaTiendas)
{
if (T.CodDpto == t.CodDpto && T.CodRetail == t.CodRetail)
{
TiendaWrapper tiend = new TiendaWrapper(T);
lstTiendas.Add(tiend);
}
}
return Ok(lstTiendas);
}
但是当我使用邮递员调用服务时,我得到这个异常。该功能应该接收两个标识的是身体,发现有这些标识的
"$id": "1",
"Message": "The request entity's media type 'multipart/form-data' is not supported for this resource.",
"ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'Tienda' from content with media type 'multipart/form-data'.",
"ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
任何帮助将是巨大的Tiendas
,预先感谢您。
编辑:
这是我如何调用邮差方法:http://localhost:1918/api/tiendas/GetTiendasPost 我在体为形式的数据添加值。
你可以请分享你如何使用邮递员?邮递员的内容是什么? – dotnetstep
你是怎么称呼这种方法的。显示UI/Fiddler /邮递员代码 – Taleeb
@RenatoEspinozaCarranza。您需要为内容类型添加标题。例如,如果您的内容类型是JSON,那么在邮递员的标题选项卡中,您应该添加 - Content-Type:application/json – Taleeb