How to Send Token in x-www-form-urlencoded API Calling in react native

1k Views Asked by At

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(),
      });
1

There are 1 best solutions below

0
On

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));