aspnet-core-jwt-authentication-api icon indicating copy to clipboard operation
aspnet-core-jwt-authentication-api copied to clipboard

unsupported media type

Open opensas opened this issue 5 years ago • 3 comments

I tried to test the app running

$ curl -d "username=test&password=test" -X POST http://localhost:4000/users/authenticate
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"0HLMEPV7RSATF:00000001"}

Same error if I try with vscode rest client like this:

POST http://localhost:4000/users/authenticate
accept: application/json
content-type: application/x-www-form-urlencoded

username=test
&password=test

I get:

HTTP/1.1 415 Unsupported Media Type
Connection: close
Date: Thu, 02 May 2019 07:36:26 GMT
Content-Type: application/problem+json; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked

{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.13",
  "title": "Unsupported Media Type",
  "status": 415,
  "traceId": "0HLMEPV7RSATG:00000001"
}

I think it would be very useful to add to the docs a curl command line to test the app

opensas avatar May 02 '19 07:05 opensas

I downloaded the vue app, and inspecting it I realized that it expects the values as a json in the body.

I tried to change it to accept form parameters, with no luck

        [AllowAnonymous]
        [HttpPost("authenticate")]
        [Consumes("application/x-www-form-urlencoded")]
        public IActionResult Authenticate([FromBody]User userParam)

I keep getting the same error, any idea?

opensas avatar May 02 '19 07:05 opensas

@opensas I use httpie instead of curl, Just post data like get style: http http://locahost:4000/users/authenticate username=test password=test this works fine for me, good luck

Linshiqi avatar Jun 26 '19 01:06 Linshiqi

change public IActionResult Authenticate([FromBody]User userParam) to public IActionResult Authenticate([FromForm]User userParam)

ajonesrock avatar Aug 28 '19 06:08 ajonesrock