最近有个需求,在某些操作时需要用公共账号发送POST请求,所以就想用GM_xmlhttpRequest来带着公共账号的Cookie做个POST
一开始把Cookie放在header里面,不管用,跑去翻了官方文档,发现要放在外面
但是放在外面也不顶用,翻资料发现GM_xmlhttpRequest的Cookie不是覆盖是加在已有Cookie的尾部一起发送
那么怎么办呢,答案是把匿名发送anonymous设置为true,这样原有的Cookie会被清除,这样指定的Cookie就能覆盖上去了
代码样例:
let cookie = '...';
GM_xmlhttpRequest({
method: "POST",
url: `...`,
data: "",
anonymous: true,
cookie: cookie,
headers: {
"Content-Type": "...",
"User-Agent": "..."
},
onload: function (response) {
alert(`操作成功`);
},
onerror: function (){
alert(`操作失败`);
}
});
本文介绍了如何在使用GM_xmlhttpRequest进行公共账号POST请求时,通过设置anonymous为true清除原有Cookie,确保指定Cookie生效。提供了一个代码示例和关键步骤。

1313

被折叠的 条评论
为什么被折叠?



