您需要使用request
模块将POST the form data添加到您的端点。服务器的响应将返回到.post()
方法。
const request = require('request');
// do not reassign "request", if you need to set properties us a different variable
// use the action= value from the form for the URL
const url = 'https://central.carleton.ca/prod/twbkwbis.P_ValLoginn';
const data = {
sid: 'username',
PIN: 'password',
};
request.post({ url: url, formData: data }, (err, response, body) => {
if (err) {
console.log('failed', err);
} else {
console.log('the response', body);
}
});
如果您对分析生成的HTML感兴趣,我推荐使用CheerioJS - 很像jQuery,但是服务器端。
https://github.com/request/request#forms – doublesharp
@doublesharp谢谢,我已经看到了,并试过它,但它仍然没有登录。 –
我刚刚发布了一个例子作为答案。确保您检查回调中的结果,以确保服务器没有响应错误等。 – doublesharp