Here I'm trying to get data from the services:
public async Task<IHttpActionResult> ValidateSesion()
{
var values = new Dictionary<string, string>{
{ "productId", "1" },
{ "productKey", "Abc6666" },
{ "userName", "OPPO" },
};
var json = JsonConvert.SerializeObject(values, Formatting.Indented);
// var content = new FormUrlEncodedContent(json);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PostAsync("http://172.116.12.172:8014/iadmin/validate", json);
var responseString = await response.Content.ReadAsStringAsync();
return Ok(responseString);
}
If I make any PostMan call, like below, the data i get looks like this:
{
"productId": "1",
"productKey": "Abc6666"
}
You can't post a raw string, you have to wrap it in a StringContent:
new StringContent(json);
This should do the trick:
public async Task<IHttpActionResult> ValidateSesion()
{
var values = new Dictionary<string, string>{
{ "productId", "1" },
{ "productKey", "Abc6666" },
{ "userName", "OPPO" },
};
var json = JsonConvert.SerializeObject(values, Formatting.Indented);
var stringContent = new StringContent(json);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PostAsync("http://172.116.12.172:8014/iadmin/validate", stringContent);
var responseString = await response.Content.ReadAsStringAsync();
return Ok(responseString);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With