-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cookie not set in Request Headers, even with 'same-origin' credentials. #349
Comments
You can't manipulate cookies manually in either XMLHttpRequest nor Can't the backend read the CSRF token from the |
@mislav I've figured it out. The fetch('/api/v2/user/me', {
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Cache': 'no-cache'
},
credentials: 'include'
}) ...duh. For others. |
Yikes. Sorry I didn't spot that. Thanks for the update |
FWIW: If you set Example call: fetch('/api/v2/user/me', {
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Cache': 'no-cache'
},
credentials: 'same-origin'
}) |
hello @chalisegrogan ,
but i dont get any cookies i use react for front and laravel for backend |
@constantinosergiou ++ having the same problem, also using React. Help, anyone? :) |
hi, appreciate any body's help. |
fetch became too much of a pain for me, so I went for axios library.. after I read this article.
https://medium.com/@shahata/why-i-wont-be-using-fetch-api-in-my-apps-6900e6c6fe78?source=linkShare-a084d3e16929-1531565170
…On Jul 14, 2018, 1:26 PM +0300, Faramarz Razmi ***@***.***>, wrote:
hi,
I also have this problem. When I remove credentials: 'include', then add option like Set-Cookie: 'value=value1', it works. But, I want to set just Cookie to have option Cookie in request headers not Set-Cookie: 'value=value1'(because the server works in Cookie: 'value=value1' syntax!)
appreciate any body's help.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Making requests to a Django API requires setting a
csrftoken
cookie. I am having trouble setting this and sending theCookie
header in afetch
request. I have looked at:I've made sure that I'm setting the
credentials
to'same-origin'
, as noted many times in the above resources. However, theCookie
header is still missing from the request. Headers seem to be properly changed for every other attribute butCookie
. I feel like I'm missing something obvious, but cannot figure out what it is. Below is the example js I'm using.You will note the header missing from the request:

I tried changing the cookie key to something other than
csrftoken
; that did not work either. Thoughts on this?The text was updated successfully, but these errors were encountered: