gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
//大屏会议 async getViewingScreenBig() { let body = {}; let option = { method: 'GET',…
- User
//大屏会议 async getViewingScreenBig() { let body = {}; let option = { method: 'GET', headers: { 'Content-Type': 'application/json', 'Referrer-Policy': 'strict-origin-when-cross-origin' } };
let response = await fetch('https://vms.wxmetro.net:1443/end/mobile/screen/review/room', option); let data = await response.json(); return data.resultData; },解决跨域问题 - Assistant
在这种情况下,你可以使用代理服务器来解决跨域问题。代理服务器可以将请求发送到第三方服务器并返回结果,从而绕过浏览器的同源策略。
以下是一个示例代码,用于在本地启动一个代理服务器:
const express = require('express'); const cors = require('cors'); const fetch = require('node-fetch'); const app = express(); app.use(cors()); app.get('/end/mobile/screen/review/room', async (req, res) => { try { const response = await fetch('https://vms.wxmetro.net:1443/end/mobile/screen/review/room'); const data = await response.json(); res.json(data); } catch (error) { res.status(500).json({ error: 'Internal Server Error' }); } }); app.listen(3000, () => { console.log('Proxy server listening on port 3000'); });将上述代码保存为
proxy.js文件,然后在命令行中运行node proxy.js启动代理服务器。现在,你可以通过访问
http://localhost:3000/end/mobile/screen/review/room来获得跨域请求的响应数据。将你的getViewingScreenBig方法中的URL替换为http://localhost:3000/end/mobile/screen/review/room即可解决跨域问题。