That was good suggestion, since the flag is set to false by default.
request.post({
uri: 'http://localhost:8080/login',
followAllRedirects:true,
form:{
user:"u",
password:"p"
}},
function(err, resp, body) {
console.log(body)
});
But even setting it to true (as above) made no difference.
*As an aside:* In curl too, an explicit use of -X POST does not go down
well with a subsequent GET redirect, so I had to use only an implicit POST
(that happens when you use the -d 'param=value' options) - this is a known
issue with some versions of curl. Not sure if something 'similar' could be
going on with the explicit call request.post(...)., or if I'm still missing
something. (I sure realize that request and curl are totally different
codebases, so just guessing wildly here. I'm not an HTTP expert either.)
On Sunday, April 17, 2016 at 7:00:44 PM UTC+5:30, Daniel R. wrote:
>
> 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] <javascript:>> [http://danielr.neophi.com/
> ]
>
> On Sat, Apr 16, 2016 at 10:42 PM, Harry <[email protected] <javascript:>>
> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> 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/6763aa9d-0cb3-477e-9236-45f74d98d562%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.