1

Segue código:

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 ..."));

Veja o retorno:

HTTP Status 415 – Unsupported Media Type Type Status Report

Message Cannot 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

Coloquei "Accept", "application/json" e mesma assim não funcionou. Me parece que está faltando colocar application/json no DeleteAsync().

Alguma solução ?

2 Respostas 2

1

Amigo, boa tarde

Você deve especificar o método HTTP a que se refere, como por exemplo Http Delete, e se necessário, informar que as informações são via Body, ou query string e assim por diante:

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);

Espero ter ajudado.

0

Achei outra solução:

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

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .