Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于GM_xmlHttpRequest请求携带Cookie的问题 #78

Open
SudoSuBash opened this issue Aug 2, 2023 · 2 comments
Open

关于GM_xmlHttpRequest请求携带Cookie的问题 #78

SudoSuBash opened this issue Aug 2, 2023 · 2 comments

Comments

@SudoSuBash
Copy link

SudoSuBash commented Aug 2, 2023

你好,Stay的创作团队:
我在编写插件的时候发现GM_xmlHttpRequest在Stay里面似乎不能携带Cookie请求API.
我写的这个插件在Userscript和Tampermonkey都可以正常请求API并且获取正确的信息,但是唯独在Stay中运行,在请求API的时候返回了"验证失败,请重新登录"的数据,经过Postman进一步分析得出是Cookie的原因.
有什么办法能让GM_xmlHttpRequest函数携带Cookie请求API呢?
这是出问题的代码:

GM_xmlhttpRequest({
            method: "GET",
            url: <url>,
            headers:<headers>,
            onload: (res) => {
                resolve(res)
            })

通过这段代码访问API时,不能够携带本地Cookie而导致API返回"验证失败,请重新登录".
已经试过并且无效的方法:

GM_xmlhttpRequest({
            method: "GET",
            url: <url>,
            headers:<headers>,
            anonymous: true,
           cookie: document.cookie,
            onload: (res) => {
                resolve(res)
            })

恳请Stay开发团队修复一下这个Bug或者给出一个解决方案!谢谢!

一个开发者,
2023.8.2

@imdabao
Copy link

imdabao commented Mar 26, 2024

我也遇到了这个问题,使用document.cookie无法获取到httponly的cookie,比如:session。使用GM_cookie能获取到,但是貌似不支持GM_cookie吧,我还没有试。

你可以试下:

GM_xmlhttpRequest({
            method: "GET",
            url: <url>,
            headers:{
                "Cookie":"k1=v1;k2=v2"
             },
            anonymous: true,
            onload: (res) => {
                resolve(res)
            })

@SudoSuBash
Copy link
Author

SudoSuBash commented Apr 5, 2024

我也遇到了这个问题,使用document.cookie无法获取到httponly的cookie,比如:session。使用GM_cookie能获取到,但是貌似不支持GM_cookie吧,我还没有试。

你可以试下:

GM_xmlhttpRequest({
            method: "GET",
            url: <url>,
            headers:{
                "Cookie":"k1=v1;k2=v2"
             },
            anonymous: true,
            onload: (res) => {
                resolve(res)
            })

这好像并不能解决我的问题(我当时试过)。这种传递cookie的方式也不能应用在tampermonkey上。现在我的脚本已经放弃了对stay的支持。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants