Node.js 在节点中发送json并请求express
我有两个节点js应用程序,一个发送post请求,如下所示:Node.js 在节点中发送json并请求express,node.js,json,express,body-parser,Node.js,Json,Express,Body Parser,我有两个节点js应用程序,一个发送post请求,如下所示: request.post({ url: url, headers: {"content-type": "application/json"}, json: {a:1,b:2} }, function (error, response, body) { //.. } ); 另一个正在尝试使用express和body解析器处理它: const express = require('e
request.post({
url: url,
headers: {"content-type": "application/json"},
json: {a:1,b:2}
},
function (error, response, body) {
//..
}
);
另一个正在尝试使用express和body解析器处理它:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/verify', (req, res,cb = (err, res) => {}) => {
var data = req.body; //returns empty json!
// ..
}
问题是,在接收端,我无法检索我正在查找的json数据。有人知道我遗漏了什么吗?将此添加到服务器端代码应该可以:
app.use(bodyParser.json())
请告诉什么是url?localhost,运行expressPlease共享完整url的另一个节点js应用请使用此代码让选项={url:'',形式:{email:'me@example.com,密码:'myPassword'}};request.post(选项、回调);