javascript - React Js Axios Post Request not receiving body back from web api -


so have web api set generate token return when send username , password same works through postman if give body

enter image description here

this works gives token , correct information when chrome, firefox or ie gives me error code this,

var d = {         username: uname,         surname: pword,         grant_type: "password",         client_id: "099153c2625149bc8ecb3e85e03f0022",     };     console.log(d);      var self = this;     return (         axios.post('http://localhost/hydraauth/oauth/token', {             headers: {                 'content-type': 'application/json',             },             data: d         }).then(function (response) {             console.log(response.data)             self.setstate({                 isloggedin: true,                 uname: uname,             }, function () {                 sessionstorage.setitem("login", true);                 sessionstorage.setitem("uname", uname)                 window.location.href = "/";             });         }).catch(function (error) {             if (error.response){             console.log(error.response)             console.log(error.response.data);             console.log(error.response.status);             console.log(error.response.headers);             } else {             window.alert("incorrect username or password or unauthorized access this.")             }         })     ); 

which gives me error in chrome

enter image description here

here error expanded

enter image description here

image of network tab in chrome response tab empty

enter image description here

axios has issue sending data via body need use npm plugin query string

and use

axios.post("http://localhost/hydraauth/oauth/token", querystring.stringify({ "username": uname, "password": pword, "grant_type": "password", "client_id": "eyjjbgllbnrfawqioijtyxz2es1dcm0tumvhy3qtsnmtu3lzdgvtin0" })) 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -