javascript - 从一个 Nodejs 函数向另一个函数发送 Post Data “mutlipart”
问题描述
我想将在下面的 post 方法中收到的相同数据发送到另一个 app.post 方法。
app.post('/sign_up', (req, res) => {
var name = req.body.fullname,
email = req.body.email,
password = req.body.password,
cpassword = req.body.cpassword;
var base64Str = req.body.image;
var obj = { name: name, email: email, password: password, cpassword: cpassword, b:base64Str };
console.log("Server Recieved: ");
console.log(obj);
//Now here want to submit this data as post to another
//app.post("/get_data", function(req, res)) { //do something else } )
});
让我知道如何实现这一目标?
解决方案
您可以为“/get_data”路由使用命名函数,并在“/sign_up”路由的末尾调用该函数。
请参阅下面的示例代码。
app.post('/sign_up', (req, res) => {
var name = req.body.fullname,
email = req.body.email,
password = req.body.password,
cpassword = req.body.cpassword;
var base64Str = req.body.image;
var obj = {
name: name,
email: email,
password: password,
cpassword: cpassword,
b: base64Str
};
console.log("Server Recieved: ");
console.log(obj);
//Now here want to submit this data as post to another
get_data(req, res);
});
app.post("/get_data", get_data);
const get_data = function(req, res)) {
//do something else
};
推荐阅读
- vba - Visual Studio 2017 中 VBA 的差异和合并
- c# - 如何修改内容并为动态用户控件创建多个实例?
- kotlin - 如何在kotlin中按块映射列表
- testing - 使用 Cypress 单击后捕获 URL(window.location 更改)
- javascript - redux 和状态机(例如 xstate)之间的实际区别是什么?
- javascript - 在服务器端渲染中访问 window.scrollY,这可能吗?
- vlan - 可以分配给单个 VLAN 的最大子网数是多少?
- android - 属性既不是名词也不是字符串
- python - 检查遵循不同属性的对象的相等性
- python - 通过拆分索引名称将 1D pandas DataFrame 重新排列为 2d