nodejs 怎么访问一个远程链接,然后输出返回的数据
我研究了半个月没明白,望大神指点
nodejs 怎么访问一个远程链接,然后输出返回的数据
我研究了半个月没明白,望大神指点
给你直接贴代码
httpApi.js
var superagent = require('superagent'),
jsonp = require('superagent-jsonp');
var httpApi = new Object(null);
/*post请求*/
httpApi.post = function (url, params, callback) {
superagent
.post(url)
// .use(jsonp)
.query(params)
.end(function (err, res) {
callback(err, res);
});
}
httpApi.post = function (url, callback) {
superagent
.post(url)
// .use(jsonp)
.end(function (err, res) {
callback(err, res);
});
}
/*get请求*/
httpApi.get = function (url, params, callback) {
superagent
.get(url)
// .use(jsonp)
.query(params)
.end(function (err, res) {
callback(err, res);
});
}
httpApi.get = function (url, callback) {
superagent
.get(url)
// .use(jsonp)
.end(function (err, res) {
callback(err, res);
});
}
exports = module.exports = httpApi;