isomorphic-fetch icon indicating copy to clipboard operation
isomorphic-fetch copied to clipboard

URLSearchParams in body doesn't set content-type to x-www-form-urlencoded

Open zmeyc opened this issue 5 years ago • 0 comments

Using URLSearchParams() as body doesn't set content-type to application/x-www-form-urlencoded. https://fetch.spec.whatwg.org section 5.2

  const body = new URLSearchParams({
    grant_type: 'client_credentials'
  })
  fetch(url, {
    method: 'POST',
    headers: {
      'accept': 'application/json',
    },
    body: body})

A workaround is to pass it explicitly. node-fetch package works as expected.

'content-type': 'application/x-www-form-urlencoded; charset=utf-8'

zmeyc avatar Nov 16 '19 21:11 zmeyc