Reputation: 3053
Here's the most minimal test case that I could reduce. It may help to convert it to use native Node HTTP or else use the request library, if you're more familiar with either one of those. But as is, I get back a bunch of jquery crap. AFAICT, the HTTP POST request sent is identical to the one programmed in curl here: https://stackoverflow.com/a/15169425/3025492
var USER = 'uuuut',
PASS = 'ppppt';
superagent
.post( 'https://pay.reddit.com/api/login/' )
.send( { api_type: 'json', rem: 'True',
user: USER, passwd: PASS } )
.end( function( res ) {
console.log( 'Session cookie: ', res.body.data.cookie || res.headers['Set-Cookie'] );
});
When done correctly, it's just supposed to set an authentication cookie.
Upvotes: 0
Views: 365
Reputation: 18956
There are several problem in your code:
form
instead of json
, so you need the method .type('form')
res.body.json.data.cookie
res.headers['set-cookie']
Full code:
superagent
.post( 'https://pay.reddit.com/api/login/' )
.type('form') // send request in form format
.send( { api_type: 'json', rem: 'True',
user: USER, passwd: PASS } )
.end( function(err, res) {
console.log( 'Session cookie: ', res.body.json.data.cookie || res.headers['set-cookie']);
});
Upvotes: 2