前言:
前言是终于整疼完考试,一个人回到家了,折腾了2个周,基本上纯玩了 ,也应该好好学习了的说,前几天桔子君想让我写一个东东能够自动续费免费vps的东东,完事同学用了个易语言轻轻松松搞定,然后我果断Google一下,大多数用的是HTTP模块,但是没用过request模块,感觉request模块很屌的样子,钻牛角尖,我就用了ruquest模块。没想到那么纠结,最后post成功但后面都没折腾,因为不会接受response的cookie。
残损的代码 ( ╯▽╰):
var request = require('request'); var Iconv = require('iconv-lite'); function checklogin() { var config = { url: 'http://idc789.com/user/usertop_login.asp', headers: { }, form: { "password": "*******", "Submit.x": "29", "Submit.y": "4", "username": "*****" } }; request.post(config, function (error, response, body) { if (!error) { console.log(body); } }) var ask = { encoding: null, url: 'http://idc789.com/user/vpsadm.asp', headers: { "cookie":"ASPSESSIONIDAQSDCDDB=CNNIMJKAJJCGBHCHFDKHFKDD" } } request.get(ask, function (error, response, body) { var str = Iconv.decode(body, 'gb2312'); var nologin = str.match(/出错啦/g); if (nologin != null) { console.log("未登录"); } else { console.log("已经登录"); } } ) }