|
electron net.request 服务端收不到请求
- const {net}=require('electron');
- const requestOptions = {
- url: 'http://localhost:3000/test',
- method: 'GET',
- };
- const request = net.request(requestOptions);
复制代码 服务端无论如何也收不到请求,经过排查发现缺少了
request.end();
net 模块请求最后一定要添加上 request.end()不然请求就会不成功
完整请求示例
- const {net}=require('electron');
- const requestOptions = {
- url: 'http://localhost:3030/test',
- method: 'POST',
- };
- const info = {
- platform: process.platform,
- version: app.getVersion(),
- mode: isDevelopment ? 'development' : 'production',
- };
- const request = net.request(requestOptions);
- request.on('response', function (response) {
- log.info('crash response =>', response);
- });
- request.on('error', error => {
- log.error('crash error =>', error);
- });
- request.write(JSON.stringify(info));
- request.end();
复制代码
|
|