Avalonia
Avalonia copied to clipboard
The avalonia browser program cannot communicate with the server
Discussed in https://github.com/AvaloniaUI/Avalonia/discussions/12115
Originally posted by zy1075984 July 9, 2023 I tried to communicate with the server in the avalonia browser program. I tried two methods, and neither of them worked properly, but there was no problem in the desktop program. 1.httpClient cannot be called because the ReadAsStringAsync method is blocked. ` private async Task GetData()
{
using (var httpClient = new HttpClient())
{
var response = await httpClient.GetAsync("https://postman-echo.com");
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsStringAsync();
}
}`
2.JSImport cannot be called because the GetHRef method is blocked.
in *.csproj
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
in main.js `const { setModuleImports, getAssemblyExports, getConfig } = await dotnet.create();
setModuleImports("main.js", { window: { location: { href: () => globalThis.window.location.href } } });`
in *.cs
[JSImport("window.location.href", "main.js")] internal static partial string GetHRef();
3.SigalR or RestSharp are also unavailable
I don't see any issue with Avalonia here nor any errors or stacktraces at all. HttpClient and web sockets do work in the Browser.
I am facing very similar issue. Not being able to invoke any communication from webassembly project. After executing ReadAsStringAsync() method, I am not receiving anything neither exception. At server side no any communication is invoked by the client. The solution works with desktop project normally.
I am closing this issue as it doesn't seem either related or valid for the browser. Also no response since.
@I4-PJ double check that you don't have any sync over async blocking calls. And you can see in the browser dev tools tab if there is anything going to the server and back. It also can be a CORS problem, which is just how web apps are.