Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST请求获取req.body不成功 #29

Open
youfak opened this issue Mar 26, 2023 · 0 comments
Open

POST请求获取req.body不成功 #29

youfak opened this issue Mar 26, 2023 · 0 comments

Comments

@youfak
Copy link

youfak commented Mar 26, 2023

版本:2.9.43
node: 18
请求类型:POST
body中数据请求格式:x-www-form-urlencoded

const { req, res, headers,body } = ctx;
exports.handleRequest = async (ctx, request) => {
 const client = req.request(async (svrRes) => {
    res.writeHead(svrRes.statusCode, svrRes.headers);
    console.log(ctx.req.body,req.body); //这样得到不到数据
    // 省略修改body代码
    svrRes.pipe(res);
 });
  req.pipe(client);
});

使用事件监听可以获得

   req.on('data',buffer=>{
   	console.log(buffer.toString());
   })

主入口是否缺少 require('body-parser') 模块导致无法解析?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant