fetch

fetch POST is returning HTTP 415, while curl goes on fine and returns result

拟墨画扇 提交于 2020-08-27 12:31:28
问题 This is what my code looks like let body = { authCode: "XXXX", clientId: "YYYYYY", clientSecret: "ZZZZZZ" }; fetch('https://api.myapp.com/oauth/token',{ method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json" }, mode: 'no-cors', body: body }).then(function(response){ console.log("response: ", response); }).catch(function(error){ console.log("could not get tokens: ", error); }) In Chrome, this is what I see I tried to do this by curl command and this is what

fetch POST is returning HTTP 415, while curl goes on fine and returns result

旧巷老猫 提交于 2020-08-27 12:29:43
问题 This is what my code looks like let body = { authCode: "XXXX", clientId: "YYYYYY", clientSecret: "ZZZZZZ" }; fetch('https://api.myapp.com/oauth/token',{ method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json" }, mode: 'no-cors', body: body }).then(function(response){ console.log("response: ", response); }).catch(function(error){ console.log("could not get tokens: ", error); }) In Chrome, this is what I see I tried to do this by curl command and this is what

What is correct way to handle fetch response

南楼画角 提交于 2020-08-23 08:05:19
问题 I have following code which I using for handling Magento 2 REST API. return new Promise((resolve, reject) => { fetch(uri, { method, headers, body: JSON.stringify(data) }) .then(response => { return response.json(); }) .then(responseData => { resolve(responseData); }) .catch(error => { reject(error); }); }); And I want to add response status checking, so I've started like this return new Promise((resolve, reject) => { fetch(uri, { method, headers, body: JSON.stringify(data) }) .then(response =

React useEffect causing: Can't perform a React state update on an unmounted component

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-22 03:00:10
问题 When fetching data I'm getting: Can't perform a React state update on an unmounted component. The app still works, but react is suggesting I might be causing a memory leak. "This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function." Why do I keep getting this warning? I tried researching these solutions: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal https://developer.mozilla.org