我試圖做一個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