Request: req.pipe(request(url)).pipe(res); can not pipe body. Can you tell me how to result it, thanks

Created on 22 Sep 2016  ·  3Comments  ·  Source: request/request

when I request a response from other server via my node server, I do this:
app.use(function (req, res) {
req.pipe(request(url)).pipe(res).
})
But I use request-debug, find that no req.body to the other server, causing much trouble.
Can you tell me how to result it.
Thanks.

stale

Most helpful comment

Thank you, I found the solution:
express default use 'app.use(body-parser('json'))', which means server get req and parser req.body to json. But pipe need stream to do. so change it to 'app.use(body-parser(raw()))'. raw() parser req.body to stream.

It's my solution.

All 3 comments

app.use(function (req, res) {
request(url).pipe(res).
})

try this
cheers!!

Thank you, I found the solution:
express default use 'app.use(body-parser('json'))', which means server get req and parser req.body to json. But pipe need stream to do. so change it to 'app.use(body-parser(raw()))'. raw() parser req.body to stream.

It's my solution.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings