Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Send POST data using the companion and using form-encoded

I am using an API that expects POST data to be form encoded ie. "Content-Type": "application/x-www-form-urlencoded"
 

I am trying to use fetch but I am maybe missing something as I am stuck as how to best send the data.

 

var data = {
      'grant_type'    : 'password',
      'client_id'     : clientID,
      'client_secret' : clientSecret,
      'username'      : username,
      'password'      : password,
    }
    
    fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: JSON.stringify(data)
    })
    .then((response) => {return response.json()})
    .then((data) => {
      func.logString(data);

I had previously gotten around this issue by using the URLSearchParams interface that worked fine in the simulator but is unsupported in iOS (so it kept failing on my device which is connected to my iPhone X)

 

So any ideas on how to proceed ? I am stuck

Best Answer
0 Votes
0 REPLIES 0