我試圖從節點+ express服務器向Arangodb上的我的Foxx服務發送post請求。發送來自節點的HTTP Post請求到Foxx服務(ArangoDB)
在節點方面:
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)
在福克斯的一面,我收到了請求,但日誌告訴我,它沒有身體:
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的側試過這樣:'回報requestify.post(路線,JSON.stringify(體));' –
@DavidThomas謝謝,我試過,但它沒有工作 – user6403833
在福克斯方面,你如何在req.body上嘗試使用JSON.stringify或JSON.parse。你也可以嘗試[request](https://github.com/request/request)模塊,我用它從node.js調用Foxx服務,並沒有任何問題,運行良好。 –