Given that you are issuing a post request, you'll need to set some of the other request options. In particular look at: followAllRedirects
-- Daniel R. <[email protected]> [http://danielr.neophi.com/] On Sat, Apr 16, 2016 at 10:42 PM, Harry <[email protected]> wrote: > Hello, > > I am using the Node request module from inside the Node shell to submit a > login form via an HTTP POST. If the login is successful, the server > redirects to a 'home' page (with an HTTP GET). > > The documentation for the request module says that any and all redirects > happen by default, and this indeed *is* happening - I can see the > redirect in the server log. > > However, on the client side, I need to be able to get hold of the (html) > response body of the final redirect. (In my present case, there is only 1 > redirect to a home page but it obviously could be more than 1 redirects > also in the general case.) > > Here's my client-side code: > > var request = require('request'); > request.post('http://localhost:8080/login', { > form: { > user:'u', > password:'p' > }}, > function(err, resp, body) { > console.log(body); > }); > > > *The problem is*, the above code prints nothing on the console! > > *Question:* How to print the response of the final (HTTP GET) redirect? > Additionally, in case of a chain of redirects, is it possible to retrieve, > on the client side, some info at least on the intermediate redirects - eg, > at minimum their URLs but, ideally, also their HTTP method types, query > parameters, and request bodies? > > *Further double-checking:* If I use curl against my server, I see the > html of the final home page just fine: > > > $ curl -L -d 'user=u' -d 'password=p' http://localhost:8080/login > <html> ... </html> > $ > > > Regards, > /HS > > PS: I had posted this earlier on SO, but got no response there! > > -- > Job board: http://jobs.nodejs.org/ > New group rules: > https://gist.github.com/othiym23/9886289#file-moderation-policy-md > Old group rules: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/00eff75c-e416-48dc-a859-b44bf0998ac0%40googlegroups.com > <https://groups.google.com/d/msgid/nodejs/00eff75c-e416-48dc-a859-b44bf0998ac0%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAETDeSA7bgOWo2jc0HqP6gvVfpKLuSLuo3YHH-xNR6Ofo7sWmA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
