[問題] node用request登入

看板Ajax作者 (ill!)時間9年前 (2016/04/06 07:21), 編輯推噓1(108)
留言9則, 2人參與, 最新討論串1/1
https://www.discogs.com/login?nologin=1&return=%2Fsell%2Fhistory%2F1985784%3F 我想用request(這個 https://github.com/request/request) 登入這個網頁 (登入form的action也是這個網址) 這是我用的code: request.post({ uri: "https://www.discogs.com/login?nologin=1&return=%2Fsell%2Fhistory%2F1985784%3F", form: {username: "xxxx", password: "yyyy"} }, function (err, res, body) { if (err) console.log(err); console.log(body); }); 不過body還是一樣的頁面 我希望能得到登入後的頁面 https://www.discogs.com/sell/history/1985784 請問我那裏弄錯了? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 108.0.72.181 ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1459898462.A.922.html

04/06 18:43, , 1F
我想可能是你node的 sessions 機制沒打開 預設是不啟
04/06 18:43, 1F

04/06 18:43, , 2F
用,所以你登入後 還是沒有伺服器要的session-cookies
04/06 18:43, 2F

04/06 18:43, , 3F
可以存取 你多宣告一個 var j = request.jar()試試
04/06 18:43, 3F

04/06 18:43, , 4F
04/06 18:43, 4F

04/06 18:46, , 5F
然後還有這句 request = request.defaults({jar:j});
04/06 18:46, 5F

04/06 18:46, , 6F
剛忘了 ,這樣登入的session-cookies 才會被記得
04/06 18:46, 6F

04/06 18:49, , 7F
如果還是不行 就要觀察你form 送出的東西 跟他登入的
04/06 18:49, 7F

04/06 18:49, , 8F
時候送出的 name 是不是一樣
04/06 18:49, 8F

04/07 12:08, , 9F
感謝回覆
04/07 12:08, 9F
文章代碼(AID): #1N14XUaY (Ajax)
文章代碼(AID): #1N14XUaY (Ajax)