I am trying to make a login screen for my react native app, but I can't get authentication token from my web api.
I try it with postman, and I can obtain the token.
I tried fetch api and adios for posting, no success.
This is my fetch code
fetch("https://ahmetkocadogan.a2hosted.com/token", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
body: JSON.stringify({
grant_type: "password",
deviceId: "ahmet",
username: "ahmet",
password: "123456",
})
}).then(response => {console.log(response);})
.catch(error => {
console.log(error);
});
}
My api token url is: https://ahmetkocadogan.a2hosted.com/token
in postman, I add headers as Accept - application/json, Content-Type - application/x-www.form.urlencoded
and body : grant_type - password , username - ahmet , password - 123456 , deviceId - ahmet
And I get the token from postman.
Any ideas? What is wrong with my fetch code?