problem fetching data using post method returns bad request :( #6786
heleopless50
started this conversation in
General
Replies: 1 comment 1 reply
-
I think it is due to the antiforgery token was not submitted with the request. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i am trying to fetch data using post method but it returns bad request
but when i use fetch data using get it works fine
i dont know the problem - i tried to debug but it doesnt reach the endpoint to execute code in it ! please help me !
this is my code :
fetch('/Accounts/Accounts/RenameAccount', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: "ahmed", city: "hehia" })
}).then(data => console.log(data));
[Route("Accounts/Accounts/RenameAccount")]
public JsonResult RenameAccount()
{
using (StreamReader reader = new StreamReader(Request.Body))
{
string requestBody = reader.ReadToEnd();
var data = JsonConvert.DeserializeObject(requestBody);
}
Beta Was this translation helpful? Give feedback.
All reactions