Answers for "react fetch request with content type x-www-form-urlencoded"

0

react fetch request with content type x-www-form-urlencoded

var details = {
    'userName': '[email protected]',
    'password': 'Password!',
    'grant_type': 'password'
};

var formBody = [];
for (var property in details) {
  var encodedKey = encodeURIComponent(property);
  var encodedValue = encodeURIComponent(details[property]);
  formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");

fetch('https://example.com/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  },
  body: formBody
})
Posted by: Guest on September-27-2021

Code answers related to "react fetch request with content type x-www-form-urlencoded"

Code answers related to "Javascript"

Browse Popular Code Answers by Language