很显然,SuperAgent 支持自定义HTTP头:
request
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' })
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end(function(err, res){
if (res.ok) {
alert('yay got ' + JSON.stringify(res.body));
} else {
alert('Oh no! error ' + res.text);
}
});
我的问题:
- 如果我通过npm下载SuperAgent,如何在SuperAgent发出的所有请求中注入自己的HTTP头?
- 注意:如果必要的话,我完全可以创建一个新的npm包来扩展SuperAgent。