<分区>
我正在尝试调用 CoinMarketCap 的公共(public) API,但它总是失败并出现以下错误:
error occured Error: getaddrinfo ENOTFOUND api.coinmarketcap.com api.coinmarketcap.com:443
当我从浏览器调用 URL 时,它会立即返回结果。代码非常简单:
const functions = require('firebase-functions');
const axios = require('axios');
exports.getBtcPrice = functions.https.onRequest((req, res) => {
axios.get('https://api.coinmarketcap.com/v1/ticker/bitcoin')
.then( (response) => {
console.log(response);
res.send("data received");
})
.catch((error) => {
console.log(error);
res.send("error occured "+ error)
});
});