The namespace WebApplication3. Controllers
{
[the Route (" API//controller ")]
[ApiController]
Public class ValuesController: ControllerBase
{
//GET the API/values
[HttpGet]
Public ActionResultThe Get ()
{
Return a new string [] {" value1 ", "value2"};
}
[HttpPost (" test ")]
Public string test (string username)
{
Return "username=" + username;
}
Wrote a simple httpPost method test, compiled after the operation can't request, prompt can not find this address, but the httpGet method can request, could you tell me what reason be?
CodePudding user response:
Request to address it and seeCodePudding user response:
https://localhost:44322/api/values/testCodePudding user response:
HttpPost (" test ") is not the test action alias?[the Route (" API//controller ")] is the corresponding API/values, so should not be normal API/values/test?
CodePudding user response:
I at Startup. The app in the cs. UseMvc change to app. UseMvcWithDefaultRoute not ();Request the address is: https://localhost:44322/values/test
CodePudding user response:
Username how to preach the cords, and hierarchy for the form, routing, url addressCodePudding user response:
UseMvcWithDefaultRoute- "this is in the use of MVC is to set the default routing path, suggest first introduce about MVC and webapi set way,
CodePudding user response:
I now is when the MVC controller to use, has removed the tags:[the Route (" API//controller ")]
[ApiController]
Just use the default routing model, write a simple HttpPost method, with no arguments, tip 404 couldn't find it
CodePudding user response: