Javascript 无法从electron main.js发出web api请求
我正在尝试测试来自electron react应用程序的ASP.NET web api调用。我在55000端口的机器上本地运行web api。我在应用程序的就绪事件中添加了api请求 此端点返回401质询,用于标题为Javascript 无法从electron main.js发出web api请求,javascript,node.js,asp.net-web-api,electron,Javascript,Node.js,Asp.net Web Api,Electron,我正在尝试测试来自electron react应用程序的ASP.NET web api调用。我在55000端口的机器上本地运行web api。我在应用程序的就绪事件中添加了api请求 此端点返回401质询,用于标题为www-authenticate的未经授权请求。我的目标是使用windows凭据调用此端点(以便electron在发出请求时通过ntlm头)。 我是不是遗漏了什么?由于某种原因,我没有得到任何回报。它只启动index.html(一个空白窗口)页面,但节点控制台上没有任何记录 impo
www-authenticate
的未经授权请求。我的目标是使用windows凭据调用此端点(以便electron在发出请求时通过ntlm头)。
我是不是遗漏了什么?由于某种原因,我没有得到任何回报。它只启动index.html(一个空白窗口)页面,但节点控制台上没有任何记录
import { app, BrowserWindow,ClientRequest,net,remote } from "electron";
import * as path from "path";
import * as url from "url";
const electron = require('electron')
var http = require('http');
let mainWindow: Electron.BrowserWindow | null;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
if (process.env.NODE_ENV == "development") {
mainWindow.loadURL(`http://localhost:3000`);
} else {
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "../index.html"),
protocol: "file:",
slashes: true,
})
);
}
mainWindow.on("closed", () => {
mainWindow = null;
});
const reque :ClientRequest = net.request({
method:'GET',
hostname:'localhost',
port:55000,
path:'...'//path to my end point
});
reque.on('response', (response:any) => {
console.log(`STATUS: ${response.statusCode}`);
response.on('error', (err:any) => {
console.log(`ERROR: ${JSON.stringify(err)}`)
});
response.on('data', (chunk:any) => {
console.log(`BODY: ${chunk}`)
});
});
console.log(reque);
reque.on('finish', () => {
console.log('Request is Finished')
});
reque.on('abort', () => {
console.log('Request is Aborted')
});
reque.on('error', (error:any) => {
console.log(`ERROR: ${JSON.stringify(error)}`)
});
reque.on('close', (error:any) => {
console.log('Last Transaction has occurred')
});
}
app.on("ready", createWindow);
app.allowRendererProcessReuse = true;