一个网站的引荐来源网址政策referer policy 设置成了 "strict-origin-when-cross-origin" , 也就无法访问其 ajax api接口,因为无法提供参数了。请问有什么办法 通过传递参数访问其该api接口以便得到数据?

一个网站的引荐来源网址政策referer policy 设置成了 "strict-origin-when-cross-origin" , 也就无法访问其 ajax api接口,因为无法提供参数了。请问有什么办法 通过传递参数访问其该api接口以便得到数据?

关注让【道友老李】来帮你解答,本回答参考通义千问大模型编写,并整理提供,如果还有疑问可以点击头像关注私信或评论。
如果答案让您满意,请采纳、关注,非常感谢!根据referer policy 设置成了 "strict-origin-when-cross-origin",表示只有在同源的情况下才会保留Referer头信息,而跨域请求时会剥离Referer头信息,导致无法直接访问ajax api接口。有以下几种方法可以绕过这个限制:
使用服务器端代理:在服务器端使用一个代理来转发请求,使得请求的Referer头信息变成同源的地址,从而绕过限制。
例如,使用Node.js搭建一个简单的代理服务器:
const http = require('http');
const request = require('request');
http.createServer((req, res) => {
const url = 'https://api.example.com' + req.url;
req.pipe(request(url)).pipe(res);
}).listen(3000, () => {
console.log('Proxy server listening on port 3000');
});
<iframe src="https://www.example.com/api" style="display:none"></iframe>
fetch('https://api.example.com/data', {
headers: {
'Origin': 'https://www.yourwebsite.com'
}
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
以上是几种绕过referer policy限制的方法,具体选择哪种方法取决于实际情况和目标网站的设置。