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
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
here error expanded
image of network tab in chrome response tab empty
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
Post a Comment