现在一个应用需要访问不同域下的TAM安全认证服务,需要模拟form表单提交到WebSEAL,先谢谢了。以下是我目前尝试的http请求写法:
var http = require('http');
var querystring = require('querystring');
var post_options = {
host: '192.168.1.22',
port: '80',
path: '/pkmslogin.form',
method: 'post',
auth: 'username:123456',
'login-form-type':'pwd',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
var post_data = querystring.stringify({
username:'username',
password:'123456',
'login-form-type':'pwd'
});
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
console.log(JSON.stringify(res.headers));
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
console.log(JSON.stringify(post_req.headers));
// post the data
//post_req.write(post_data);
post_req.end();
雷雷
原生的api当然也可以,不过更推荐用github上7000 stars的request
看介绍:
Form 直达连接:https://github.com/request/request#forms