How to Use Javascript's Fetch to get POST Request Data? -


i trying make post request using javascript's fetch method described here.

i readablestream instead of usual json response, such jquery, angular, whatever.

my code here: https://jsbin.com/vuwilaviva/edit?css,js,output

var request = new request('https://httpbin.org/post', {     method: 'post',      mode: 'cors',     data: 'the sky green',     redirect: 'follow',     headers: new headers({         'content-type': 'text/plain'     }) });   // use it! fetch(request).then(function(resp) {   console.log('logging response...')   console.log(resp); }); 

the test api endpoint works fine postman, curl, etc, sure using fetch wrong, , it's not issue api (it returns whatever string passed data):

enter image description here

edit: current answer doesn't data returned post request - it's found in logged json:

enter image description here

response.json should used this

fetch(request) .then(response => response.json()) .then(json => console.log(json)); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -