http://api.81p.net/api?p=json&t=jisupk10&token=15414985AABD5796&limit=1,各位大神,怎么样获得这个接口的数据呢???新手,麻烦请附上代码,感谢!!!! 自己的代码如下,但是报错; var http = require(“http”);
var options = { // host: 'api.81p.net/api?p=json&t=jisupk10&token=15414985AABD5796&limit=1’ host: ‘api.81p.net’, path: ‘/api?p=json&t=jisupk10&token=15414985AABD5796&limit=1’ };
http.get(options, function (http_res) { // initialize the container for our data var data = “”;
// this event fires many times, each time collecting another piece of the response
http_res.on("data", function (chunk) {
// append this chunk to our growing `data` var
data += chunk;
});
// this event fires *one* time, after all the `data` events/chunks have been gathered
http_res.on("end", function () {
// you can use res.send instead of console.log to output via express
console.log(data);
});
});
能先看下文档? https://nodejs.org/api/http.html#http_http_get_url_options_callback 补充下,自己刷新下dns, mac终端执行 sudo killall -HUP mDNSResponder
var http = require('http');
http.get('http://api.81p.net/api?p=json&t=jisupk10&token=15414985AABD5796&limit=1', (res) => {
let data = ''
res.on('data', (chunk) => data+=chunk)
res.on('end', (chunk) => console.log(data))
})
@leemove 这个报错,
@quanpf2481 这个是你的网络问题吧,我这边运行了一下没问题
@leemove 能不能把你的代码贴出来看一下呢???
@quanpf2481 一字不差,就是上面的代码.
这个一般就是网络问题。
可能你需要代理 proxy。