当我尝试使用net.request时,它会在电子中返回错误“无法读取未定义的'属性'请求。”
这是我的main.js代码
const electron = require('electron');
const {app, Menu} = electron;
const {BrowserWindow} = require('electron');
var mainWindow = null;
app.on('ready', function(){
mainWindow = new BrowserWindow({
width: 500,
height: 300
});
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.openDevTools();
mainWindow.setMenu(null);
mainWindow.on('closed', function () {
mainWindow = null;
});
const {net} = require('electron');
const request = net.request('https://github.com');
request.on('response', (response) => {
console.log('STATUS: ${response.statusCode}')
console.log('HEADERS: ${JSON.stringify(response.headers)}');
response.on('data', (chunk) => {
console.log('BODY: ${chunk}');
});
response.on('end', () => {
console.log('No more data in response.');
});
});
request.end();
});
我找不到出错的地方。有人建议解决这个问题吗?任何帮助将不胜感激
答案 0 :(得分:1)
它不会在1.4.5
[评论亮点:]
另外,根据发行说明,net
api仅适用于https://github.com/electron/electron/releases/tag/v1.4.5上的1.4.5