我已经阅读了大量关于 SO 的问题,尝试了多种方法但没有成功。我的问题很相似,但我发帖是因为我已经尝试了所有方法但仍未成功。
我想检查我的服务器上是否维护着一个用户 session 。我有一个网络服务,它根据收到的 cookie 返回一个 bool 值。
浏览器负责在请求服务器时发送 cookie(如果有)。因此,当我通过 chrome-extension 请求时,理论上浏览器也应该发送 cookie。然而,事实并非如此。
这是我的代码:-
content.js
fetch('https://zoffers.in/apis/shops/get_aff_url/', {
credentials: 'include',
mode: 'cors',
async: false,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Hubot',
login: 'hubot',
})
})
.then(function(data) {
})
.catch(function(error) {
})
list .json
{
"manifest_version": 2,
"version": "0.1",
"content_scripts": [{
"matches": [
"https://*/*/"
],
"js": ["js/content.js"],
"run_at": "document_start"
}],
"browser_action": {
// "default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Click here!"
},
"permissions": [
"identity",
"identity.email",
"tabs",
"notifications",
"cookies",
"https://zoffers.in/"
]
}
我做错了什么?谁能帮我解决这个问题。
已更新
content.js
message = {
'event_type': 'Event1',
}
chrome.runtime.sendMessage(message);
background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
if(request.event_type === 'Event1'){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
fetch('https://zoffers.in/apis/shops/get_aff_url/', {
credentials: 'include',
mode: 'cors',
async: false,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Hubot',
login: 'hubot',
})
})
.then(function(data) {
})
.catch(function(error) {
})
}
}
}
);
已将 background.js
添加到 manifest.json 文件。但还是不行。
最佳答案
您可以使用标准 Cookies api并访问任何可用 URL 的 cookie。
关于google-chrome-extension - Chrome 扩展程序 - 不在请求中发送 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56368828/
相关文章:
python - 无法编码响应 : datetime. datetime(2019, 5, 29,
git - 一个 git 子模块卡在错误的提交 ('submodule update' 不工作)
reactjs - 我们如何在使用 react 最终形式时在组件中设置状态
google-chrome - 本地主机 Web 应用程序访问远程 API 时未设置 Cookie
python-3.x - 如何在 Python 中创建具有每个变量值之间差距的堆积条形图
sql-server - SQL Server Management Studio v18 的命令行
azure-active-directory - 企业应用程序中基于组角色的授权
python - 是否可以在 Snakemake 中有一个可选的输出文件?