-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
怎么用koa发出一个请求呢?用request.get方法吗?怎么拿到响应呢? #21
Comments
不太懂你的意思,是用http发请求吗,那和express的一样。request的话,看看这个,不知道是不是你想要的 var request = require("request");
var co = require("co");
function requestPromise(options) {
return new Promise(function (resolve, reject) {
request(options, function(err, response, body) {
if (err) reject(err);
resolve(body);
});
});
}
co(function* () {
var body = yield requestPromise('http://www.baidu.com');
console.log(body);
}) |
非常感谢,我刚学nodejs后台相关的东西;然后看了koa的ctx相关的API,唯一发现一个get方法,但又苦于找不到该方法的使用;我以为可以这样: 但。。。 |
看文档 request.get(field) 这个是返回请求的header的某个属性信息的 router.get('/domain', function* () {
console.log(this.request.headers);
console.log(this.request.get('Connection'));
this.body = 'end';
}); 这样应该能看懂了 |
@chouchou900822 |
RT
The text was updated successfully, but these errors were encountered: