I have this in the server side (C#, core 3.1):
[EnableCors("CorsApi")]
[Route("[action]", Name = "DeleteFile")]
[HttpPost]
public List<string> DeleteFile(string pathFile)
{
string commandDelete = "rm " + pathFile;
List<string> results = ExecuteCommand(commandDelete, true);
return results;
}
and I have this in the client side (react):
(async () => {
const response = await fetch('https://localhost:7198/api/Proj/DeleteFile', {
method: 'POST',
body: JSON.stringify({
pathFile: srcFile,
}),
headers: {
'Content-type': 'application/json; charset=UTF-8'
},
})
const data = await response.json()
console.log(data)
})()
but the POST not work. it's work only when I send the parameter inside the url, like:
'https://localhost:7198/api/Proj/DeleteFile?pathFile=' + srcFile.
Why it's happend? And how can I fix it?
Thank You.