如何使用带有httpOnly cookie或basic auth的window.fetch() [英] How do I use window.fetch() with httpOnly cookies or basic auth

查看:91
本文介绍了如何使用带有httpOnly cookie或basic auth的window.fetch()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firefox中使用 window.fetch()和Chrome。出于某些原因,fetch()不会发送任何cookie。现在这不会有问题,因为我可以使用

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 } })

但这不适用于httpOnly cookies。

But this won't work for httpOnly cookies.

推荐答案

好的,我在浏览Mozilla开发者网络后发现了一点,并尝试了凭证选项。

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'

将发送饼干。

这篇关于如何使用带有httpOnly cookie或basic auth的window.fetch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆