Error in API Rest POST - Windows Forms

Asked

Viewed 228 times

0

I’m trying to register (POST) this endpoint https://geradornf-prod.herokuapp.com/ (is a Simple API I made with Django Rest)

I’m using Windows Forms C#

Follow the call:

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(UtilDAO.UrlApi());
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.PostAsJsonAsync("/emitente", emitente);
                return response;
            }

And you’re giving me back 500

{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
   Connection: keep-alive
   Transfer-Encoding: chunked
   X-Frame-Options: SAMEORIGIN
   Date: Tue, 02 Aug 2016 23:05:36 GMT
   Server: gunicorn/19.6.0
   Via: 1.1 vegur
   Content-Type: text/html
}}

Someone would know what it could be?

o GET Works!

In case you wanted to see the API see in : https://github.com/leonardocintra/GeradorNf-e-API

1 answer

0


I found the error of the 500.

the address was like this:

HttpResponseMessage response = await client.PostAsJsonAsync("/emitente", emitente);

I thought passing the URL on client.BaseAddress with the "/issuer" was sufficient

The way it works would be like this:

HttpResponseMessage response = await client.PostAsJsonAsync(client.BaseAddress.AbsolutePath + "emitente/" , emitente);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.