【发布时间】:2017-07-14 14:27:09
【问题描述】:
我正在尝试从节点 + 快递服务器向我在 Arangodb 上的 Foxx 服务发送发布请求。
在节点端:
var route = arangopi + '/edge/' + col.name ;
var body = {data: data, from: fromId, to: toId} ;
console.log('|| body :', route, body) ;
>> || body : http//XXX/_db/my-DB/my-foxx-service/path/to/visitedBy { data: { isBackup: true, text: '', isHint: true, continuance: 3441.5 }, from: 'Drop/27237133', to: 'Bot/41116378' }
return requestify.post (route, body)
在 Foxx 方面,我收到了请求,但日志告诉我它没有正文:
router.post('/path/to/:param', function (req, res) {
console.log ('|| body :', req.body)
var data = req.body ;
var result = api.DoSomething (req.stateParams.param, data)
res.send(result)
})
.response(joi.object().required(), 'Entry stored in the collection.')
.summary('Summary')
.description('Description')
>> || body : [Object { "binarySlice" : function binarySlice() { [native code] }, "asciiSlice" : function asciiSlice() { [native code] }, "base64Slice" : function base64Slice() { [native code] }, "ucs2Slice" : function ucs2Slice() { [native code] }, "hexSlice" : f...
在节点方面,我也尝试了“请求”模块。
return request.post(route, {form:body}, function (error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
return response ;
});
我从 Foxx 得到相同的日志。
我做错了什么?
这是我在 Foxx 界面上的操作截图。无法指定请求正文进行测试是否正常?
【问题讨论】:
-
你是否从 node.js 端尝试过这个:
return requestify.post (route, JSON.stringify(body)); -
@DavidThomas 谢谢我试过了,但没用
-
在 Foxx 方面怎么样,在 req.body 上尝试 JSON.stringify 或 JSON.parse。你也可以试试request模块,我用它从node.js调用Foxx服务,没有任何问题,运行良好。
-
@DavidThomas 我试过了,但没有成功。我复制了问题中的“请求”代码,你看到错误了吗?我现在正在尝试其他库。奇怪的是,我收到的请求没有包含所有库的正文!
-
@DavidThomas 当您检查您的查询时,您是否获得相同的 Web 界面参数?还有一个“身体”吗?
标签: node.js http arangodb foxx requestify