This is a try of call a REST API that as an authentication token with React.js. I'm sending the token request as POST and it's been read as GET, can someone help me please?
componentDidMount() {
fetch("theURL/api-token-auth/", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
email: "EMAIL",
password: "PASSWORD"
}
})
.then(res => {
if (res.ok) {
return res.json();
} else {
throw Error(res.statusText);
}
})
.then(json => {
this.setState({
isLoaded: true,
token: json
});
})
.catch(error => console.error(error));
}
POST, so the error might be in the backend. However, the data you want to send should probably be in the body instead of in the headers. Trybody: JSON.stringify({ email: email, password: password })fetch(route, {method: 'POST', headers: {'Content-Type': 'application/json', auth: AUTHCODE}, body: JSON.stringify({data})})The authcode should only be used to confirm the user is coming for a good location. You should use the body for all the other data.