我试图通过302重定向发送JSON.这在ExpressJS中是否可行.API声明可以添加正文res.json().例如:
res.json(302, {'name': 'larry'}).
Run Code Online (Sandbox Code Playgroud)
在接收端(重定向也在那里),身体是空的.以下是一些示例代码:
发送应用程序
app.get('/hello', function(req,res){
var data = {'name': 'larry'};
res.set('location', 'http://www.example.com/sending');
res.json(302, data);
});
Run Code Online (Sandbox Code Playgroud)
接收应用程序
app.get('/sending', function(req,res){
console.log('Body: ' + req.body)
res.send(req.body);
});
Run Code Online (Sandbox Code Playgroud)
注意:302的响应标头显示数据的正确内容长度,但接收端显示空对象.