fetch POST is returning HTTP 415, while curl goes on fine and returns result
fetch()
does not expect a JavaScript object at body
. curl
command and fetch()
pattern are not the same. Use body: JSON.stringify(<javascript plain object>)
.
Note: The
body
type can only be aBlob
,BufferSource
,FormData
,URLSearchParams
,USVString
orReadableStream
type, so for adding aJSON
object to the payload you need to stringify that object.
See Fetch with ReadableStream for status of implementation of ReadableStream
set as value for body
.
you must define Accept
and Content-Type
headers like that and stringify your data object
const params = { headers: { 'Accept': "application/json, text/plain, */*", 'Content-Type': "application/json;charset=utf-8" }, body: JSON.stringify(yourObject), method: "POST" };fetch(url, params) .then(data => { console.log('data', data)}) .then(res => { console.log('res', res) }) .catch(error => { console.log('error', error) });