These are chat archives for request/request

2nd
Feb 2015
miguelalche
@miguelalche
Feb 02 2015 11:56
Hey!
I'm trying to log in to a webpage
And it seems it's allowing me
however when I do a get request in the callback of my post request
and I log the body of the page, it seems as I am logged out!
It's very strange since when I log the body of my POST request, it says: <html><body>You are being <a href="www.exampleurl.com">redirected</a>.</body></html>
How can this happen? are cookies the problem? I thought cookies where set automatically
simo
@simov
Feb 02 2015 12:03
try with {jar:request.jar()} in the options of your request
miguelalche
@miguelalche
Feb 02 2015 12:40
Thanks, I wasn't doing that
however it still doesn't work
simo
@simov
Feb 02 2015 12:41
paste your entire request call here
miguelalche
@miguelalche
Feb 02 2015 12:41
I even tried sending the response headers of the POST request as the headers of the GET

var request = require('request');
var tough = require('tough-cookie');

var cheerio = require('cheerio');

var request = request.defaults({jar: true});
var j = request.jar()
var request = request.defaults({jar:j});

var credentials = {
'user[email]': 'user',
'user[password]': 'pass',
utf8: '✓',
authenticity_token: 'LLK1lp4o7yjrknD0GmPMWmEEYH9umsbAAE7Xwo2sf04='
};

request.post({
uri: 'http://argentina.cdopromocionales.com/users/sign_in',
jar: j,
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body: require('querystring').stringify(credentials)
}, function(err, res, body){
if(err) {
callback.call(null, new Error('Login failed'));
return;
}

console.log(res.headers);

request.get({url:'http://argentina.cdopromocionales.com/product_variants/8311', jar: j }, function(err, res, body) {
    if(err) {
        callback.call(null, new Error('Request failed'));
        return;
    }

    var $ = cheerio.load(body);
    var text = $('.exchange-rate').text();
    console.log(text);
    console.log(res.headers);

});

});

It didn't paste nicely. hmm

var request = require('request');
var tough = require('tough-cookie');

var cheerio = require('cheerio');

var request = request.defaults({jar: true});
var j = request.jar()
var request = request.defaults({jar:j});

var credentials = {
'user[email]': 'user',
'user[password]': 'pass',
utf8: '✓',
authenticity_token: 'LLK1lp4o7yjrknD0GmPMWmEEYH9umsbAAE7Xwo2sf04='
};

request.post({
uri: 'http://argentina.cdopromocionales.com/users/sign_in',
jar: j,
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body: require('querystring').stringify(credentials)
}, function(err, res, body){
if(err) {
callback.call(null, new Error('Login failed'));
return;
}

console.log(res.headers);

request.get({url:'http://argentina.cdopromocionales.com/product_variants/8311', jar: j }, function(err, res, body) {
    if(err) {
        callback.call(null, new Error('Request failed'));
        return;
    }

    var $ = cheerio.load(body);
    var text = $('.exchange-rate').text();
    console.log(text);
    console.log(res.headers);

});

});

oh well.
miguelalche
@miguelalche
Feb 02 2015 12:46
here it is
thanks!
simo
@simov
Feb 02 2015 12:53
so what exactly is the problem, which request doesn't work? the first or the second one
miguelalche
@miguelalche
Feb 02 2015 12:54
I found one interesting thing:
1) even if I input wrong credentials in the body of the POST request I'd get "You're being redirected"
The problem is that the second one renders the page as If I wasn't logged in
Other interesting thing is that I doesn't redirect me (thats how I'm able to log that body)
*it doesn't redirect me
simo
@simov
Feb 02 2015 12:56
try out with https://github.com/request/request-debug and see if you can find anything
probably your first request is not correct either
miguelalche
@miguelalche
Feb 02 2015 12:58
I'll try thanks!
I'll need to take a course on node ...
Uzo Olisemeka
@Akamaozu
Feb 02 2015 14:43

hi there!

I'm using a module that has a ReadableStream input (https://github.com/mscdex/node-ftp).
I noticed request can stream (with .pipe).
How do I get the ReadableStream object from request?
I want to use it with ftp.put()

simo
@simov
Feb 02 2015 15:16
ftp.put(request.get()) probably
if it accepts a stream
request() returns a duplex stream (read/write)
I think you can figure out the rest :)