'; // 替换为实际API密钥
// 准备请求参数
const params = {
// 可以添加其他参数
};
// 使用axios
axios.get(apiUrl, { params })
.then(response => {
try {
// 如果是JSON响应
if (typeof response.data === 'object') {
console.log(JSON.stringify(response.data, null, 2));
} else {
console.log(response.data);
}
} catch (e) {
console.log(response.data);
}
})
.catch(error => {
console.error('请求失败:', error.message);
});
// 或者使用原生https模块
/*
const querystring = require('querystring');
const query = querystring.stringify(params);
https.get(`${apiUrl}?${query}`, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
try {
console.log(JSON.parse(data));
} catch {
console.log(data);
}
});
}).on('error', (err) => {
console.error('Error:', err.message);
});
*/