gpt4 book ai didi

使用 Electron 的 CORS 请求

转载 作者:行者123 更新时间:2023-12-03 12:20:27 26 4
gpt4 key购买 nike

我无法通过我的 Electron 应用发出 CORS 请求。我已经设置了所需的webSecurity

mainWindow = new BrowserWindow({
width: 1024,
height: 768,
show: false,
webPreferences: { webSecurity: false }
});

然后尝试从 zoho 服务器获取数据

fetch('https://books.zoho.com/api/v3/contacts\\?organization_id\\=12345',
{
method: 'get',
headers: {
'Authorization': "Zoho-authtoken 984fe68e7f564c6bs01ee9ffb1dsa140",
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
})
.then(_result =>{
console.info("_result",_result);
})

我发送的 header (来自网络选项卡),响应为 400

GET /api/v3/contacts/?organization_id\=12345 HTTP/1.1
Host: books.zoho.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
authorization: Zoho-authtoken 987984fe68e7f564c6bs01ee9ffb1dsa140
X-DevTools-Request-Id: 21105.4
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) basic-electron-react-boilerplate/0.7.0 Chrome/59.0.3071.115 Electron/1.8.8 Safari/537.36
content-type: application/x-www-form-urlencoded;charset=UTF-8
Accept: */*
Referer: http://localhost:8080/index.html
Accept-Encoding: gzip, deflate
Accept-Language: en-GB

当我 curl

时,此请求有效

curl https://books.zoho.com/api/v3/contacts\?organization_id\=12345 -H 'Authorization: Zoho-authtoken 984fe68e7f564c6bs01ee9ffb1dsa140' -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"

最佳答案

我在用这个

const { app, BrowserWindow } = require("electron");
app.commandLine.appendSwitch("disable-features", "OutOfBlinkCors");

关于使用 Electron 的 CORS 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52890757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com