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

如何修改Req.body呢,我试了一下好像不行呢 #33

Open
SprintClouf opened this issue Jul 24, 2023 · 2 comments
Open

如何修改Req.body呢,我试了一下好像不行呢 #33

SprintClouf opened this issue Jul 24, 2023 · 2 comments

Comments

@SprintClouf
Copy link

exports.handleRequest = async (ctx, request) => {
const { req, res } = ctx;

// 获取 POST 请求的 Body
let requestBody = '';
req.on('data', (chunk) => {
requestBody = chunk.toString();
});
req.on('end', async () => {
requestBody = JSON.parse(requestBody);

// 在这里根据需要修改请求的 Body 数据
try {
  requestBody.query_model.sentry_business_id = '-1';
} catch (errr) {
  console.log(errr)
}

//     // 继续处理其他逻辑
const client = request({...req.headers, data: JSON.stringify(requestBody) }(svrRes) => {
  res.writeHead(svrRes.statusCode, svrRes.headers);
  svrRes.pipe(res);
});

try {
  req.pipe(client);
  await client.write('{"name": "Join"}', 'utf8', () => {
  	console.log(23131323)
  });
} catch (err) {
  console.log(err)
}

});
};

@avwo
Copy link
Member

avwo commented Jul 24, 2023

如果只是简单修改内容可以用:https://wproxy.org/whistle/rules/resMerge.htmlhttps://wproxy.org/whistle/rules/resReplace.html

@SprintClouf
Copy link
Author

赞,reqMerge完美解决了这个问题

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

2 participants