需求描述
想要判断某接口,是否支持跨域接口
快速验证方案
- 通过控制台找到该接口,并拷贝出fetch请求的代码(里面会包含相应的参数)
- 打开目标网站,把下面的代码在console中复制。如果允许跨域,network会成功发送请求。否则会报CORS跨域错误。
拷贝出来的fetch代码如下
fetch("https://test.xx.com/api/company/afterSale/dictionaries", {
"headers": {
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
"app-version": "TOWER_20230202114601",
"authorization": "xxxxxxxxxx",
"gwfp": "xxxxxxxxxx",
"sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"source": "supplier"
},
"referrer": "https://test.xxx.com/demo/test1",
"referrerPolicy": "no-referrer-when-downgrade",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。