the dotnet core webapi code is as follows
[HttpGet]
[EnableCors("CMSCorsConfig")]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
[EnableCors("CMSCorsConfig")]
public ActionResult<string> Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
[EnableCors("CMSCorsConfig")]
public void Post([FromBody] string value)
{
//throw new Exception("HELLO FROM POST");
}
axios request code is as follows:
export function write (title, name) {
return axios({
url: "/values/",
method: "post",
data: { title, name }
})
}
the error is as follows:
I succeeded in calling axios to another API,
export function write (title, name) {
return axios({
url: "/values/",
method: "get"
})
}
I can succeed with the following rewriting, but I can"t get the value
[HttpPost]
[EnableCors("CMSCorsConfig")]
public string Post( string title,string name)
{
return title;
}
can be called successfully if changed to this way, but the return value is always null
how to adjust, and under what circumstances is [FromBody] used