如何从 api( https://jsonplaceholder.typicode.com/posts/1 ) 获取数据并使用履行在操作中显示?
我的代码:
function apiCall(agent){
https.get('https://jsonplaceholder.typicode.com/posts/1', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data).explanation);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
我收到一个错误:
在函数中:getaddrinfo ENOTFOUND jsonplaceholder.typicode.com jsonplaceholder.typicode.com:443