1、向java后台取数据 //测试post请求 var http = require(‘http’); var querystring = require(‘querystring’); var post_options = { host: ‘xxx.xx.xx.xx’, port: ‘80’, path: ‘/’, method: ‘post’, headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ } };
var post_data = querystring.stringify({ phone:‘0000’, password:‘1’, });
// 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();
2、通过http模块取出的数据,怎样替换掉下面的user exports.doLogin = function(req,res){ var user = { phone:‘xxxxx’, password:‘xxxx’ } if(req.body.phone === user.phone && req.body.password === user.password){ req.session.phone = user.phone; res.redirect(’/teacher’); }else{ res.redirect(’/login’); } };
求解啊~~~