nodejh
2/28/2018 - 6:04 AM

fetch POST 使用 application/x-www-form-urlencoded

How to make a post request with JSON data in application/x-www-form-urlencoded

const searchParams = Object.keys(params).map((key) => {
  return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
}).join('&');

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  },
  body: searchParams
})