How to use fetch post json and Sending cookies ?
See original GitHub issueHow are you. I have a question: How to use fetch post json and Sending cookies ? My code:
return fetch('/category/save.json' , {
credentials: 'include',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(function(response){
if (response.status >= 200 && response.status < 300) {
return response
} else {
var error = new Error(response.statusText);
error.response = response;
throw error
}
}).then(function(response) {
return response.json();
}).then(function(json) {
console.log('parsed json', json)
}).catch(function(ex) {
console.log('parsing failed', ex)
});
Why cookie not send? Thank you.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Fetch API with Cookie - Stack Overflow
I called POST /api/auth and see that cookies were successfully received. Then calling GET /api/users/ with credentials: 'include' and got 401 ...
Read more >Using the Fetch API - MDN Web Docs
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses.
Read more >Sending Cookies With JavaScript Fetch - YouTube
In this video I talk about an issue you may run into when trying to use the fetch function in JavaScript.Need one-on-one help...
Read more >Cookie missing in HTTP request when using Fetch API
I store a CSRF token in a cookie, which is used by the server to validate client-side HTTP POST requests. The server responds...
Read more >How to Pass Cookies with Fetch or Axios Requests - Sabe.io
This will make a request to the server at http://example.com/data.json and return the response as a JSON object, then log the data to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I only use parameter credentials: ‘include’ , The cookie Can send. But I use parameter credentials: ‘include’ and headers: { ‘Content-Type’: ‘application/json’ } to post json data, Why cookie not send?
why & solution
https://github.com/github/fetch#sending-cookies https://github.com/github/fetch#receiving-cookies