【发布时间】:2020-12-13 09:12:28
【问题描述】:
我希望能够将数据从一台服务器发送到另一台服务器,在同一设备上启动(开始时)。我有这个:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const urlEncodedParser = bodyParser.urlencoded({extended: false});
app.post('/test', urlEncodedParser, (request, response) =>
{
console.log(request.body);
});
app.listen(9999);
console.log('Server started on port 9999');
const unirest = require('unirest');
unirest.post('http://127.0.0.1:9999/test').headers({'Accept': 'application/json', 'Content-Type': 'application/json'}).send({"test1": 123321, "test2": "321123"})
.then((response) =>
{
console.log(response.body);
});
看起来合乎逻辑,但 console.log(request.body); 给出了空对象 {} 但在发布请求中我确实使用 .send 发送了一些数据。如何访问请求中的数据?
【问题讨论】:
标签: node.js express http post unirest