如何使用node.js(express.js)将带有上传文件的post multi/form-data表单重新发送到不同的服务器?

vit*_*cny 10 node.js express

我将带有文件(enctype ="multipart/form-data")的表单发布到node.js(express.js框架),并且只想发送这个相同的发布请求,就像它只是发送到不同的服务器一样.node.js中最好的方法是什么?

Iva*_*anM 9

删除express.bodyParser并尝试这样的管道:

req.pipe(request('http://host/url/')).pipe(res)
Run Code Online (Sandbox Code Playgroud)

  • 这是mikeal /请求请求吗? (2认同)

Zim*_*Zim 6

您可以尝试使用Mikeal的Node.js请求(https://github.com/mikeal/request).它会是这样的:

app.post('/postproxy', function(req, res, body){
    req.pipe(request.post('http://www.otherserver.com/posthandler',body)).pipe(res);
});
Run Code Online (Sandbox Code Playgroud)