javascript - How to understand which cookie the client should send in a node.js request? -


i'm trying scrape through website need's authentification. after login session cookie set, want send server everytime subsequent request.

when set options this:

  const options = {     hostname: www.exaple.com,     port: 443,     path: '/loginpage',     headers: {       auth: 'basic' + new buffer('username:password').tostring('base64'),     },     method: 'post',   }; 

i response back:

statuscode: 200 headers: {    'cache-control': 'private',   'content-type': 'text/html; charset=utf-8',   'x-frame-options': 'sameorigin',   'set-cookie':   [ 'asp.net_sessionid=oka0kl302tcza53btd3arzam; path=/; httponly',   'remarketingrandomgroup=16; expires=sun, 19-aug-2018 22:00:00 gmt; path=/',   '__requestverificationtoken=drdasuhybpe6c6vizvcayixdr90tvjg06jz6l88i3iongyi7mvqno9kg_bpcdtsxajtaykziixbr_tq0smy1hwu5s1a1; path=/; httponly' ],   date: 'sun, 20 aug 2017 08:06:51 gmt',   connection: 'close',   'content-length': '4083'  } 

everything looking smooth far if try set cookie subsequent request this:

    const options2 = {       hostname: www.example.com,       port: 443,       path: '/dashboard',       headers: {         cookie: res.headers['set-cookie'],       },       method: 'get',     }; 

all 307 error redirects me login page...

i realized res.headers['set-cookie'] array. after realizing i've tried stringify array gave me same error again. tried use following cookie:

  • 'asp.net_sessionid=oka0kl302tcza53btd3arzam expires=sun, 19-aug-2018 22:00:00 gmt'
  • '__requestverificationtoken=drdasuhybpe6c6vizvcayixdr90tvjg06jz6l88i3iongyi7mvqno9kg_bpcdtsxajtaykziixbr_tq0smy1hwu5s1a1 expires=sun, 19-aug-2018 22:00:00 gmt'
  • 'asp.net_sessionid=oka0kl302tcza53btd3arzam'
  • '__requestverificationtoken=drdasuhybpe6c6vizvcayixdr90tvjg06jz6l88i3iongyi7mvqno9kg_bpcdtsxajtaykziixbr_tq0smy1hwu5s1a1'

of course i've looked other questions on pointing repository: https://github.com/request/request use not answer question how figure out cookie sent server client. should mention 1 site multiple cookies no issue here.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -