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)
{
}
}
Firstly,as maghazade
said,there are two endpoints for the post method
.You can try to use [HttpPost("teststring")]
as ferhrosa
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.
[Route("api/[controller]/[action]")]
[ApiController]
public class VideoWallController : ControllerBase
{
// GET: api/<ValuesController>/Get
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<ValuesController>/Get/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<ValuesController>/prova
[HttpPost]
public string prova()
{
return "true;";
}
// POST api/<ValuesController>/teststring
[HttpPost]
public void teststring([FromBody]string test)
{
}
// PUT api/<ValuesController>/Put/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<ValuesController>/Delete/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
And if you want to pass string test
from Body,you need to add [FromBody]
and select JSON
in postman.