Khaja Moizuddin

Khaja Moizuddin

  • 163
  • 11.5k
  • 1.9m

Getting 500 Internal Server Error in POST Request HttpClient

Dec 16 2019 9:17 AM
I am getting 500 Internal Server error with endpoint POST request using HttpClient C# with the access token
 
 HttpClient client = HeadersForCreateUser(accessToken);
 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Uri.EscapeUriString(client.BaseAddress.ToString()));
request.Content = new StringContent(JsonBody, Encoding.UTF8, "application/json"); 
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response1 = client.PostAsync(Uri.EscapeUriString(client.BaseAddress.ToString()), request.Content).Result;
 
private static HttpClient HeadersForCreateUser(string accessToken)
{
HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = false };
HttpClient client = new HttpClient(handler);
client.BaseAddress = new Uri(endpointURL);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
client.DefaultRequestHeaders.Add("apikey", apikeyvalue);
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
//client.DefaultRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded");
return client;
}
 
Is anyone has faced this kind of issue, please give a reply. 
 
 

Answers (5)