Skip to content

Instantly share code, notes, and snippets.

@jasonslyvia
Created June 27, 2014 09:27
Show Gist options
  • Save jasonslyvia/710a4b99ee6817cab55a to your computer and use it in GitHub Desktop.
Save jasonslyvia/710a4b99ee6817cab55a to your computer and use it in GitHub Desktop.
模拟登录
var http = require('http');
var postData = '__EVENTTARGET=winLogin%24sfLogin%24ContentPanel1%24btnLogin&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTE4ODU0MTIxMDdkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYJBQh3aW5Mb2dpbgUQd2luTG9naW4kc2ZMb2dpbgUWd2luTG9naW4kc2ZMb2dpbiRjdGwwMAUfd2luTG9naW4kc2ZMb2dpbiR0eHRVc2VyTG9naW5JRAUcd2luTG9naW4kc2ZMb2dpbiR0eHRQYXNzd29yZAUed2luTG9naW4kc2ZMb2dpbiRjYnhTYXZlTXlJbmZvBR53aW5Mb2dpbiRzZkxvZ2luJENvbnRlbnRQYW5lbDEFJ3dpbkxvZ2luJHNmTG9naW4kQ29udGVudFBhbmVsMSRidG5Mb2dpbgUIV25kTW9kYWy%2Bbc6QsNOdH7ZtF07lnmmRBXbUK%2F7AWPgOr2Q5ybbyRQ%3D%3D&X_CHANGED=true&winLogin%24sfLogin%24txtUserLoginID=123456&winLogin%24sfLogin%24txtPassword=7890&winLogin_Hidden=false&WndModal_Hidden=true&X_TARGET=winLogin_sfLogin_ContentPanel1_btnLogin&winLogin_sfLogin_ctl00_Collapsed=false&winLogin_sfLogin_ContentPanel1_Collapsed=false&winLogin_sfLogin_Collapsed=false&winLogin_Collapsed=false&WndModal_Collapsed=false&X_STATE=e30%3D&X_AJAX=true';
var options = {
hostname: 'mis.sse.ustc.edu.cn',
method: 'post',
path: '/default.aspx',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': 'ASP.NET_SessionId=bvjuayqjlvskpb4ypn0cy2wy',
'Content-Length': postData.length
}
};
var req = http.request(options, function(res){
res.setEncoding('utf8');
res.on('end', function(){
var newCookie = 'ASP.NET_SessionId=bvjuayqjlvskpb4ypn0cy2wy;' + res.headers['set-cookie'];
console.log(newCookie);
var req = http.request({hostname: 'mis.sse.ustc.edu.cn', path: '/homepage/StuDefault.aspx', headers: {'Cookie': newCookie}}, function(res){
res.setEncoding('utf8');
res.on('data', function(chunk){
console.log(chunk);
});
});
req.end();
});
});
req.write(postData);
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment