문제

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.

도움이 되었습니까?

해결책

There are several problem in your code:

  1. the post request in form instead of json, so you need the method .type('form')
  2. the returned cookie at: res.body.json.data.cookie
  3. headers in superagent must be in lower case: 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']);
    });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top