Reputation: 453
I am going to use fetch to post
const token = 'ABCD123:A'
await fetch(path, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: token=encodeURIComponent(token),
});
encodeURIComponent(token) should be ABCD123%3AA
My server should get encoded value, decode value and then store to DB.
But in my api server, it gets non-encode body: token=ABCD123:A
Should server gets encoded value?
And I have tested same encoded value on Postman, my server is getting encoded value.
As my server gets different value, is it Fetch API problem or my fetch request issue?
Upvotes: 0
Views: 1666
Reputation: 4961
I think you forgot to make Object
for Body,
const token = 'ABCD123:A'
await fetch(path, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: {
'token':encodeURIComponent(token)
}
});
Upvotes: 1