POST Error with Rest API - Windows Forms

0

I'm trying to make a POST this endpoint link (it's a simple API I've done 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 it's returning me 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
}}

Would anyone know what it could be?

GET Works!

If you wanted to see the API, check it out: link

    
asked by anonymous 03.08.2016 / 01:02

1 answer

0

I found the 500 error.

the address was like this:

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

I found that passing the URL in client.BaseAddress to the "/ issuer" was sufficient

The way it works would look like this:

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