Javascript 当前使用SuperAgent构造查询字符串的机制是什么?
我正在尝试使用。但是.data()似乎不再存在Javascript 当前使用SuperAgent构造查询字符串的机制是什么?,javascript,node.js,httpclient,Javascript,Node.js,Httpclient,我正在尝试使用。但是.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 {
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);
}
});
结果:
Object #<Request> has no method 'data'
对象#没有方法“数据”
尝试将.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
*/
在最新版本的SuperAgent(0.18.0)中,上述答案不适用于我。我不得不使用
query
函数()
谢谢,干杯!这些文档似乎有点落后于源代码——我确实打开了它们进行检查,但显然没有看到。这个答案已经过时了。您不能将
send
与get
一起使用:
request.get("/search").query({ search: 'query' }).end(callback);