'How to Send Token in x-www-form-urlencoded API Calling in react native
this type of API = x-www-form-urlencoded calling is new for me. please guide me on how can I send my token with this I tried this way but its not working
let data = new URLSearchParams();
data.append("account_type", asyncData.data?.account_type);
const response = await fetch(URLs.update, {
method: "POST",
params:{ token }
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
},
body: data.toString(),
});
Solution 1:[1]
using fetch method, this is how you can implement it :
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer "+token);
var requestOptions = {
method: 'POST',
redirect: 'follow',
headers: myHeaders,
};
fetch(URLs.update, requestOptions)
.then(response => response.json())
.then(result => console.log(resutlt))
.catch(error => console.log(error));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chikabala |
