I am trying to make a POST request using Javascript's fetch method as described here.
I get a ReadableStream instead of a usual json response, such as what I would get with jQuery, Angular, whatever.
My code is here: https://jsbin.com/vuwilaviva/edit?css,js,output
var request = new Request('https://httpbin.org/post', {
method: 'POST',
mode: 'cors',
data: 'The sky is green',
redirect: 'follow',
headers: new Headers({
'Content-Type': 'text/plain'
})
});
// Now use it!
fetch(request).then(function(resp) {
console.log('Logging response...')
console.log(resp);
});
The test API endpoint works fine with postman, curl, etc, so I am sure I am using fetch wrong, and it's not an issue with the API (it just returns whatever string is passed to it as data):
Edit: The current answer doesn't actually get the data returned by the post request - it's nowhere to be found in the logged json:


bodyproperty.