如何提出要求并将其从电子应用发送到服务器

时间:2019-05-13 17:41:36

标签: node.js electron nfc smartcard rfid

这是我下面的代码! 我想在电子应用程序的后台运行此读卡器,当检测到卡时,应使用请求api将卡的uid发送到服务器

const { NFC } = require('nfc-pcsc');
const { pretty } = require('./pretty.js');

const nfc = new NFC(); // optionally you can pass logger

pretty.info('nfc module init');
nfc.on('reader', async reader => {
    console.log(`${reader.reader.name}  device attached`);
    reader.aid = 'F222222222';
    reader.on('card', async card => {
       pretty.info(`card detected`, reader, card);
       const requestApi = {
             method: 'post',
             protocol: process.env.API_PROTOCOL,
             hostname: process.env.API_HOSTNAME,
             port: process.env.API_PORT,
             path: '/',
       };

       const request = net.request(requestApi);

       request.on('response', data => {
           pretty.info(`card uid response from server -> ${JSON.stringify(data)}`)
       });

       request.end({
          uid: card.uid
       });

       pretty.info(`card info request`, request);
   });
   ....
});
....

但我不确定这是否正确

0 个答案:

没有答案