[英]redash GET request works on POSTMAN but not on axios
On redash I have a query.在重划我有一个查询。 It's
GET
request.这是
GET
请求。 On POSTMAN
it works well.在
POSTMAN
上运行良好。 Query example:查询示例:
https://app.redash.io/<company name>/api/queries/<query id>/results.json?api_key=<api key>
But on axios
it throws:但是在
axios
上它会抛出:
Network error
网络错误
And on console written:在控制台上写:
Access to XMLHttpRequest at
https://app.redash.io/<company name>/api/queries/<query id>/results.json?api_key=<api key>
from origin ' http://localhost:3000 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.Access to XMLHttpRequest at
https://app.redash.io/<company name>/api/queries/<query id>/results.json?api_key=<api key>
from origin ' http://localhost:3000 ' has被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”header。
My axios
default configs:我的
axios
默认配置:
import axios from 'axios/index';
import { appVersion } from '../../constants/defaultValues';
const { CancelToken } = axios;
export const source = CancelToken.source();
const api = axios.create({
timeout: 5 * 60 * 1000,
headers: {
version: appVersion,
},
cancelToken: source.token,
});
export default api;
It's not from your code.这不是来自您的代码。 your code is right
你的代码是正确的
CORS is a browser feature. CORS 是浏览器功能。 Servers need to opt into CORS to allow browsers to bypass same-origin policy.
服务器需要选择加入 CORS 以允许浏览器绕过同源策略。 Your server would not have that same restriction and be able to make requests to any server with a public API.
您的服务器将没有相同的限制,并且能够向任何具有公共 API 的服务器发出请求。
You can read more about Cross-Origin Resource Sharing您可以阅读有关跨域资源共享的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.