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
):
edit: current answer doesn't data returned post request - it's found in logged json
:
response.json should used this
fetch(request) .then(response => response.json()) .then(json => console.log(json));
Comments
Post a Comment