我試圖將一個字符串發送到我的網頁API像這樣:發送JSON字符串作爲一個POST到asp.net網頁API
public IList<Product> GetProducts(string myString)
{
IList<Product> retVal = null;
using (var client = GetClient())
{
HttpContent httpContent = new StringContent(myString, Encoding.UTF8, "application/json");
// HTTP POST
HttpResponseMessage response = client.PostAsync("api/products", httpContent).Result;
}
return retVal;
}
在我的ProductsController我的操作方法是這樣的:
// POST: api/products/filter
[HttpPost("filter")]
public IList<Product> Filter(string filter)
{
}
由於某種原因,過濾器參數保持爲空。任何想法爲什麼?
嗯我用FromBody嘗試過,仍然爲空。如果發送一串json,content-type應該是application/json嗎? –