HTTP Status 415 - Unsupported Media Type

0

Follow the code below:

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
var result = await httpClient.DeleteAsync(new Uri("URL do Site ..."));

See the return:

  

HTTP Status 415 - Unsupported Media Type Type Status Report

     

Message Can not consume content type

     

Description The origin server is refusing to service the request   because the payload is in a format not supported by this method on the   target resource.

     

Apache Tomcat / 8.5.23

I put "Accept", "application/json" and it still did not work. I seem to be missing application/json no DeleteAsync() .

Any solution?

    
asked by anonymous 08.12.2018 / 19:09

2 answers

0

I found another solution:

HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Delete, "URL do Site ...")
{
    Content = new StringContent(string.Empty, Encoding.UTF8, "application/json")
};
HttpResponseMessage response = await httpClient.SendAsync(httpRequest);
    
08.12.2018 / 21:12
0

Friend, good afternoon

You must specify the HTTP method to which it refers, such as Http Delete, and if necessary, inform that the information is via Body, or query string and so on:

HttpRequestMessage request = new HttpRequestMessage
{
    Content = new StringContent("[YOUR JSON GOES HERE]", Encoding.UTF8, "application/json"),
    Method = HttpMethod.Delete,
    RequestUri = new Uri("[YOUR URL GOES HERE]")
};

await httpClient.SendAsync(request);

I hope I have helped.

    
26.12.2018 / 17:45