i have to call an api in my c# class with httpclient. API need the content-type header, i want to get the response as json so i add content-type : application/json to headers in postman and do the post request and it works perfect :
But if i write something else in content-type api returns html code. I have to do the exactly same thing as postman in C# Here is my example code :
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("adress");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "adress");
request.Content = new StringContent(myjson, Encoding.UTF8, "application/json");
var y = await client.SendAsync(request);
var x = await y.Content.ReadAsStringAsync();
But the result is always HTML not json.