Not calling RestAPI #492

Closed
opened 2026-01-29 16:41:03 +00:00 by claunia · 5 comments
Owner

Originally created by @graylobo on GitHub (May 17, 2020).

  • 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

Originally created by @graylobo on GitHub (May 17, 2020). <!-- Please search existing issues to avoid creating duplicates. --> <!-- Which version of Electron.NET CLI and API are you using? --> <!-- Please always try to use latest version before report. --> * **Version**: 8.31.2 <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> <!-- What target are you building for? --> * **Target**: <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> <img width="911" alt="20200517_203428" src="https://user-images.githubusercontent.com/37823841/82143714-eeed8200-9880-11ea-9207-749135ec2c33.png"> I'm trying to call RestAPI data, using httpclient library in nuget. <img width="1917" alt="20200517_205822" src="https://user-images.githubusercontent.com/37823841/82146507-cc119c80-9885-11ea-9519-305e6c2ab290.png"> <img width="1385" alt="20200517_213450" src="https://user-images.githubusercontent.com/37823841/82146582-46422100-9886-11ea-8220-b41e2f613bb9.png"> 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
claunia added the bug label 2026-01-29 16:41:03 +00:00
Author
Owner

@konstantingross commented on GitHub (May 17, 2020):

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<List>("http://localhost:8001/api/students");

image

@konstantingross commented on GitHub (May 17, 2020): Your ElectronNET port does not match the port of the RestAPI call. Add following line to your Program.cs: webBuilder.UseStartup<Startup>(); webBuilder.UseUrls("http://*:8001"); //e.g. 8001 RestAPI.razor: Students = await http.GetJsonAsync<List<Student>>("http://localhost:8001/api/students"); ![image](https://user-images.githubusercontent.com/6459825/82153392-70381b00-9867-11ea-8825-2c4e89965a42.png)
Author
Owner

@graylobo commented on GitHub (May 18, 2020):

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?

@graylobo commented on GitHub (May 18, 2020): 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](https://user-images.githubusercontent.com/37823841/82168690-5267c600-98fa-11ea-99c6-082e6dd3ce51.png) ![20200518_112653](https://user-images.githubusercontent.com/37823841/82168797-9955bb80-98fa-11ea-8e2b-7826d3978383.png) 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?
Author
Owner

@konstantingross commented on GitHub (May 18, 2020):

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/")

@konstantingross commented on GitHub (May 18, 2020): 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/")`
Author
Owner

@GregorBiswanger commented on GitHub (May 18, 2020):

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

Did we solve your problem?

@GregorBiswanger commented on GitHub (May 18, 2020): The safest way would be: `new MenuItem { Label = "Home", Click = () => Electron.WindowManager.BrowserWindows.First().LoadURL($"http://localhost:{BridgeSettings.WebPort}/")` Did we solve your problem?
Author
Owner

@graylobo commented on GitHub (May 19, 2020):

Yes, it works perfect. Thanks a bunch!

@graylobo commented on GitHub (May 19, 2020): Yes, it works perfect. Thanks a bunch!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#492