Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Estou tentando fazer o teste de consumo da api, porem é retornado o seguinte erro. O que poderia ser?

An unhandled exception occurred while processing the request.
UnsupportedMediaTypeException: No MediaTypeFormatter is available to read an object of type 'LivroApi' from content with media type 'text/html'.

System.Net.Http.HttpContentExtensions.ReadAsAsync<T>(HttpContent content, Type type, IEnumerable<MediaTypeFormatter> formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)

Stack Query Cookies Headers
UnsupportedMediaTypeException: No MediaTypeFormatter is available to read an object of type 'LivroApi' from content with media type 'text/html'.
System.Net.Http.HttpContentExtensions.ReadAsAsync<T>(HttpContent content, Type type, IEnumerable<MediaTypeFormatter> formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
System.Net.Http.HttpContentExtensions.ReadAsAsync<T>(HttpContent content, Type type, IEnumerable<MediaTypeFormatter> formatters, IFormatterLogger formatterLogger)
System.Net.Http.HttpContentExtensions.ReadAsAsync<T>(HttpContent content, IEnumerable<MediaTypeFormatter> formatters)
System.Net.Http.HttpContentExtensions.ReadAsAsync<T>(HttpContent content)
Alura.WebAPI.WebApp.HttpClients.LivroApiClient.GetLivroAsync(int id) in LivroApiClient.cs
+
            return await responseMessage.Content.ReadAsAsync<LivroApi>();
Alura.ListaLeitura.WebApp.Controllers.LivroController.Detalhes(int id) in LivroController.cs
+
            var model = await _api.GetLivroAsync(id);
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
1 resposta
solução!

Oi Igor, tudo bem?

Por favor, tente usar:

ReadAsStringAsync

no lugar de:

ReadAsAsync

E veja se funciona. Dessa forma, o conteúdo vai ser lido como string, independente do content-type.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software