0
我尝试将json传递给nodejs post方法。但是我收到错误“必须指定搜索查询。”。我已经指定了搜索字符串并过滤了代码。你能建议导致这个错误的原因吗?如何将json传递给nodejs请求发布方法?
POSTMAN中的相同请求。
//Load the request module
var express = require('express');
var request = require('request');
var app = express();
//Lets configure and request
request({
url: 'http://host:8080/rest/1.0/search',
qs: {query: 'nodejs*'},
method: 'POST',
json: {
filter:
{
community: ['33862a97-44e5-4de5-9206-db0a61dd83ca'],
vocabulary: ['b80f3576-0642-4049-bb07-d72a0dd9e3e0','48029bb8-0585-4ed5-afaa-55014aebfcb3'],
type: {asset:['00000000-0000-0000-0000-000000011001']},
},
fields: ['name']
}
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log(response.statusCode, body);
}
});
app.listen(8080);
'request()'将数据发布到'/rest/1.0/search?query = nodejs%2A'。这是预期的路径还是应该在'json'字段中传递查询?这与你的问题无关,但不需要设置'headers',添加'json'字段会自动为你添加'“Content-type:application/json”标题。 –
查询应该在json字段中传递。让我在这里附上邮差屏幕。 – user2848031