I'm trying to pass a Dictionary<string,string> object as a parameter to my web api method but if I inspect the log file it always comes through with a count of 0:
Web api method:
[HttpPost]
[ActionName("SendPost")]
public void SendPost([FromBody] Dictionary<string,string> values)
{
using (var sw = new StreamWriter("F:\\PostTest.txt", true))
{
sw.WriteLine("Number of items in the dictionary - " + values.Count);
}
}
Logic which calls the web api:
public HttpResponseMessage Send(string uri, string value)
{
HttpResponseMessage responseMessage = null;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(URI);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new FormUrlEncodedContent
(
new Dictionary<string, string> { { "value", value } }
);
responseMessage = client.PostAsync(uri, content).Result;
}
return responseMessage;
}