在不使用 Node.jsexpress
模块的情况下,我可以使用模块读取两个 POST 数据变量https
吗?
我的代码工作正常,只是我需要从请求中获取两个POST请求值(许可证和照片)。如何从 POST 请求中提取两个部分?
const https = require('https');
const fs = require('fs');
const options = {
secure: true,
key: fs.readFileSync('ssl/key.pem'),
cert: fs.readFileSync('ssl/public.pem'),
ca: fs.readFileSync('ssl/cap1_led_com.ca-bundle')
};
https.createServer(options, function (req, res)
{
let body = '';
if (req.method === 'GET' && req.url === '/')
{
res.writeHead(200, {'Content-Type': 'text/html'});
fs.readFile('./http-form.html', 'UTF-8', (err, data) => {
if (err)
throw err;
res.write(data);
res.end();
});
}
else if (req.method === 'POST')
{
req.on('data', (data) => {
body += data;
});
req.on('end', () => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(body, () => {
res.end();
});
});
}
else
{
res.writeHead(404, {'Content-Type': 'text/html'});
res.end(`<h1>404 ERROR could not find that Page</h1>`);
}
}).listen(443);