mik*_*ana 2 javascript httpclient node.js
我试图使用SuperAgent .data()根据文档构造一个查询字符串.但是.data()似乎不再存在.
superagent
.get(URL)
.data({ 'screen_name': USER, 'count': '1' })
.end(function(response){
if (response.ok) {
console.log('yay got ' + JSON.stringify(response.body));
} else {
console.log('Oh no! error ' + response.text);
}
});
Run Code Online (Sandbox Code Playgroud)
结果是:
Object #<Request> has no method 'data'
Run Code Online (Sandbox Code Playgroud)
试图取代.data与.send
根据来源中的评论:
/**
* Send `data`, defaulting the `.type()` to "json" when
* an object is given.
*
* Examples:
*
* // querystring
* request.get('/search')
* .send({ search: 'query' })
* .end(callback)
*
* // multiple data "writes"
* request.get('/search')
* .send({ search: 'query' })
* .send({ range: '1..5' })
* .send({ order: 'desc' })
* .end(callback)
*
* // manual json
* request.post('/user')
* .type('json')
* .send('{"name":"tj"})
* .end(callback)
*
* // auto json
* request.post('/user')
* .send({ name: 'tj' })
* .end(callback)
*
* // manual x-www-form-urlencoded
* request.post('/user')
* .type('form')
* .send('name=tj')
* .end(callback)
*
* // auto x-www-form-urlencoded
* request.post('/user')
* .type('form')
* .send({ name: 'tj' })
* .end(callback)
*
* @param {String|Object} data
* @return {Request} for chaining
* @api public
*/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2064 次 |
| 最近记录: |