I am trying to hit an API from C# code. I am unable to get the response and receiving the status code "500 - Internal Server error".
Found the reason that the "Charset-UTF8" is getting appended in the request header
When i tried to hit the API in Fiddler without "Charset-UTF8", I am able to get the response in Fiddler and postman. With the "Charset-UTF8" i get the same 500 internal server error. The content type is application/json.
I even tried each and every charaset encoding methods UTF-8,16,32, unicode and default format from C# code, gives the same error.
Please let me know how to remove the CharSet(appending) from the API request Header.
please go through code i have attached
HttpClient client1 = new HttpClient();
client1.BaseAddress = new Uri("i have third party url");
client1.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
client1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", userName, password))));
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, client1.BaseAddress);
StringContent content = new StringContent(JsonConvert.SerializeObject("working request"));
request.Content = content;
client1.SendAsync(request)
.ContinueWith(responseTask =>
{
Console.WriteLine("Response: {0}", responseTask.Result);
});