When i try to post the raw text with postman the server answer 405 not allowed. I try to add
app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
services.AddCors();
without any solution.
Whis is the code of the application:
[Route("api/[controller]")]
[ApiController]
public class VideoWallController : ControllerBase
{
// GET: api/<ValuesController>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<ValuesController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<ValuesController>
[HttpPost]
public string prova([FromBody] VideoCallBack test)
{
return "true;";
}
[HttpPost]
public void teststring(string test)
{
}
// PUT api/<ValuesController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<ValuesController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
2
Answers
If you want to reach that endpoint using the
/teststring
suffix, you need to put that in the endpoint template:Or, as @maghazade said, you can just reach the endpoint using the controller URL, without a suffix:
https://localhost:44336/api/videowall
Also, the CORS settings are not needed to access the API using Postman. CORS is used only to configure the API access through a web application running on a web browser.
Firstly,as
maghazade
said,there are two endpoints for the post method
.You can try to use[HttpPost("teststring")]
asferhrosa
said.You can also add[action]
to[Route("api/[controller]")]
,so that routes of actions will include their action names.If you add other actions with post method,the routes will not conflict anymore.And if you want to pass
string test
from Body,you need to add[FromBody]
and selectJSON
in postman.result: