express怎样将java后台的接口和前台验证连接起来?
发布于 7 年前 作者 ycjcl868 6781 次浏览 最后一次编辑是 6 年前 来自 问答

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’); } };

求解啊~~~

回到顶部