laravel - React JS Fetch Returns Empty Response but Postman Does Not -
i have react js application trying log in token-based api (that developing, using laravel 5.5 , laravel passport). i'm trying implement basic login (login using username , password, receive token server once verified, use token future queries).
the code i'm using fetch below:
function loginapi(username, password) { return fetch(loginurl, { method: 'post', headers: { 'content-type': 'application/json', }, body: json.stringify({ grant_type: 'password', client_id: clientid, client_secret: clientsecret, username: username, password: password }) }).then(handleapierrors) .then(response => response.json) }
it's worth noting it's not entirely complete, i'm trying determine response i'm getting back.
i've solved normal issues 1 encounters, cors problems, issue i'm encountering response api just... empty. in network tab of chrome's developer tools, if inspect request directly, response empty.
however, if make exact same query postman, results expect.
what issue here? why exact same query return different results?
.json function , needs invoked. try..
.then(response => response.json())
you're returning .json parsing function.
Comments
Post a Comment