Electron.net: Not calling RestAPI

Created on 17 May 2020  路  5Comments  路  Source: ElectronNET/Electron.NET


  • Version: 8.31.2

  • Target:



20200517_203428
I'm trying to call RestAPI data, using httpclient library in nuget.

20200517_205822
20200517_213450

It works fine in the browser, but if I build it with electron.net in the same environment and click it,
there is no response.
github code link is below
https://github.com/graylobo/BlazorTron
Can I fix this issue? thanks in advance

bug

Most helpful comment

The safest way would be:
new MenuItem { Label = "Home", Click = () => Electron.WindowManager.BrowserWindows.First().LoadURL($"http://localhost:{BridgeSettings.WebPort}/")

Did we solve your problem?

All 5 comments

Your ElectronNET port does not match the port of the RestAPI call.

Add following line to your Program.cs:
webBuilder.UseStartup();
webBuilder.UseUrls("http://*:8001"); //e.g. 8001

RestAPI.razor:
Students = await http.GetJsonAsync>("http://localhost:8001/api/students");

image

Thank you. It works well thanks to your advice.
However, How can i get bact to the main page (_Host.cshtml) if i in new page? (e.g. json link page)
20200518_112120

20200518_112653

I try to new MenuItem { Label = "Home", Accelerator = "CmdOrCtrl+H",Role = MenuRole.undo }``
but it doesn't work.

And if I want to debugging electron.net, is this answer is the best way to do it yet?
https://github.com/ElectronNET/Electron.NET/issues/298
Is it normal for a breakpoint not to be recognized at electron.net runtime even if a breakpoint is specified?

Try this but I don't know if this is best practice:
new MenuItem { Label = "Home", Click = () => Electron.WindowManager.BrowserWindows.First().LoadURL("http://localhost:8001/")

The safest way would be:
new MenuItem { Label = "Home", Click = () => Electron.WindowManager.BrowserWindows.First().LoadURL($"http://localhost:{BridgeSettings.WebPort}/")

Did we solve your problem?

Yes, it works perfect. Thanks a bunch!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ThuCommix picture ThuCommix  路  3Comments

GregorBiswanger picture GregorBiswanger  路  4Comments

lyy0808 picture lyy0808  路  6Comments

cdespinosaagmx picture cdespinosaagmx  路  3Comments

litch0 picture litch0  路  4Comments