I am trying to redirect to another url immediately after my 1st url request is completed. The reason for that is because in order to open 2nd url, it requires the 1st url session cookie. It means 2nd url can only open if I open the 1st url prior to that action.
var request = require('request');
var j = request.jar();
request({
url: first_url,
jar: j,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
var cookies = j.getCookieString(first_url);
console.log("1st url cookie: "+ cookies);
request(second_url, function(body) {
var cookies2 = j.getCookieString(second_url);
console.log("2st url cookie: "+ cookies2);
console.log(body);
})
I modified my code as shown above to pass session cookies. However, my 2nd URL still cannot be opened. My console output shows both urls have the same session id, so I only assume the session cookie is passed correctly.
1st url cookie: JSESSIONID=DD4ACC4D65F024BD06D53A648A5B4DE3
2st url cookie: JSESSIONID=DD4ACC4D65F024BD06D53A648A5B4DE3
{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
The way I verified session cookie is required on my project is to open 1st URL on browser first, then copy and paste the 2nd URL link to open the 2nd link. Without launching the 1st URL, 2nd link will not open and eventually timeout the request.
Please advice again and maybe I am not looking at the right direction.