简体   繁体   中英

Restful API returning 404 from Post request and not generated token

I'm building a Restful API on .Net Core and it's returning a 404 locally when I test it with Postman

This authentication method takes the login info via a User class which I'm sending as a simple json...

{
    "Username": "USER",
    "Password": "PASSWORD"
}

The routing and login info check is working since it gets to the "return OK(...)" with a generated token. But Postman gets a 404 back instead of the token. Is there another setting that's missing? Should I be returning something else?

[Route("api/[controller]")]
[ApiController]
public class AuthController : ControllerBase
{       
    [AllowAnonymous]
    [HttpPost]
    [Route("token")]
    public IActionResult Post([FromBody]User user)
    {
        //if login info wrong then return

        //create token

        var serialized_token =  new { token = new JwtSecurityTokenHandler().WriteToken(token) };

        return Ok(serialized_token);        
    }
}

I'm using a standard local URL: https://localhost:[PORT_NUMBER]/api/Auth/token .

This is exactly what I'm getting back via Postman...

Could not get any response There was an error connecting to https://localhost:[PORTNUMBER]/api/Auth/token .

Why this might have happened: The server couldn't send a response: Ensure that the backend is working properly Self-signed SSL certificates are being blocked: Fix this by turning off 'SSL certificate verification' in Settings > General Proxy configured incorrectly

It looks like it happens because Postman rejects untrusted Self-signed SSL certificate provided by your local server. Try to disable SSL verification in the Postman settings: Click on the marked icon below and then click "Setting":

在此处输入图片说明

Then switch off "SSL certificate verification": 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM