我的问题是:我需要使用axios库从API中获取一些数据,但在某些情况下,它就是不起作用。
这是一个有效的示例:
const RAPIDAPI_API_URL = 'https://cbsservis.tkgm.gov.tr/megsiswebapi.v3/api/parsel/40.89253647288918/29.236472547054294/';
const RAPIDAPI_REQUEST_HEADERS = {
'Content-Type': 'application/json'
};
axios.get(RAPIDAPI_API_URL,{ headers: RAPIDAPI_REQUEST_HEADERS })
.then(response => {
const data = response;
console.log(data);
})
.catch(error => console.error('On create error', error));但是当RAPIDAPI_API_URL的值更改为"http://jsonplaceholder.typicode.com/users“时,它会抛出以下错误:
Network Error
at e.exports (https://unpkg.com/axios@0.19.2/dist/axios.min.js:2:9633)
at XMLHttpRequest.l.onerror (https://unpkg.com/axios@0.19.2/dist/axios.min.js:2:8398)发布于 2020-04-24 18:50:30
你必须通过https而不是http来加载请求。查找示例here
const RAPIDAPI_API_URL = 'https://jsonplaceholder.typicode.com/users';
const RAPIDAPI_REQUEST_HEADERS = {
'Content-Type': 'application/json'
};
axios.get(RAPIDAPI_API_URL,{ headers: RAPIDAPI_REQUEST_HEADERS })
.then(response => {
const data = response;
console.log(data);
})
.catch(error => console.error('On create error', error));https://stackoverflow.com/questions/61405999
复制相似问题