关联 issues:提供类似 Obsidian requestUrl 的方法 · Issue #8702 · siyuan-note/siyuan (github.com)
本人非计算机专业,只零散的学习过 JavaScript 的基础语法,基础比较差,希望大佬们回答的时候可以附上链接,我去学习一下 🙏
使用场景:希望实现微信读书 Cookie 续期。需要在请求头携带带旧 Cookie,通过获取返回标头的 Set-Cookie 部分。
Obsidian 的插件 使用 requestUrl | Obsidian 插件开发文档 方法实现这个功能。
类似 fetch() 方法,使用 HTTP/HTTPS 请求 URL, 没有任何跨域限制。
export function requestUrl(request: RequestUrlParam | string): RequestUrlResponsePromise;
思源目前似乎没有类似的方法,我想知道怎么做才能实现我需要的效果。
做过以下尝试:
- 直接在 axios 的 header 设置 Cookie
import axios from "axios"; axios.get('https://weread.qq.com', { headers: { cookie: 'some cookie' }, withCredentials: true, })
结果:报错 Refused to set unsafe header "cookie"
- 在 fetch 请求设置 header
fetch('https://weread.qq.com', { method: 'GET', headers: {'Cookie': 'some cookie'}, redirect: 'follow', credentials: 'include' });
结果:Cookie 被过滤
import axios from 'axios'; import { wrapper } from 'axios-cookiejar-support'; import { CookieJar } from 'tough-cookie'; const jar = new CookieJar(my_cookie); const client = wrapper(axios.create({ jar })); await client.get('https://example.com');
结果:Cookie 被过滤