简体   繁体   English

ExpressJS / Request - GET后发出POST请求

[英]ExpressJS/Request - Make a POST request after GET

I am new to node.js, so bear with me here. 我是node.js的新手,所以请耐心等待。 I am trying to make a POST request after a GET. 我想在GET之后发出一个POST请求。 Idea is once user hits the homepage, I want to redirect that user to salesforce and do an OAUth dance. 想法是一旦用户点击主页,我想将该用户重定向到salesforce并进行OAUth舞蹈。 I am using expressJS and mikeal's request. 我正在使用expressJS和迈克尔的请求。 This is the code I have so far 这是我到目前为止的代码

server.get('/', function(req, res){

var client_id = "xxx";
var client_secret = "xxx";
var redirect_uri = "https://192.168.233.105:8000/callback";
var grant_type = "authorization_code";


var remotereq = request.post('https://na1.salesforce.com/services/oauth2/token').form(

{"client_id":client_id,
"client_secret":client_secret,
"redirect_uri":redirect_uri,
"grant_type":grant_type,
"immediate":'true'
}

);


//How do I get the expressJS res object to use the remotereq object? 

});

When I hit the home page, the request just hangs. 当我点击主页时,请求就会挂起。 I am thinking I have to somehow get the expressJS response object to play nice with the mikeal/request object. 我想我必须以某种方式让expressJS响应对象与mikeal / request对象一起玩。 How do I connect the two together? 我如何将两者连接在一起?

You can pipe the result of request.post directly to res : 您可以将request.post的结果直接传递给res

remotereq.pipe(res);

That would send the result to the client verbatim, including all original headers. 这会将结果逐字地发送给客户端,包括所有原始标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM