How do I use window.fetch() with httpOnly cookies or basic auth

荒凉一梦 提交于 2019-11-29 00:48:18

问题


I'm playing around with window.fetch() in Firefox and Chrome. For some reasons, fetch() doesn't send any cookies. Now that wouldn't be a problem, as I can send them using

fetch('/something', { headers: { Cookie: document.cookie } })

But this won't work for httpOnly cookies.


回答1:


Okay, I found out after reading on the Mozilla Developer Network a bit more and trying out the credentials option.

Looks like the credentials option is what I should have looked for.

fetch('/something', { credentials: 'same-origin' }) // or 'include'

Will send the cookies.



来源:https://stackoverflow.com/questions/30013131/how-do-i-use-window-fetch-with-httponly-cookies-or-basic-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!