Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Problem send Json HttpClient

$
0
0

Hi there

I have a problem with send Json to API Rest.

Code

using (var client = new HttpClient())
{
  client.BaseAddress = new Uri("SomeURL");
  client.DefaultRequestHeaders.Accept.Clear();
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

  var response = await client.PostAsync("/SomeAction", new StringContent(JsonConvert.SerializeObject(Model).ToString(), Encoding.UTF8, "application/json"));


  return await Task.FromResult(JsonConvert.DeserializeObject<Foo>(await response.Content.ReadAsStringAsync()));
}

Result anytime is Bad Request, but test this in PostMan work correctly.. so i think the json data cannot include in request. Any idea?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>