Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

The avalonia browser program cannot communicate with the server

Open zy1075984 opened this issue 1 year ago • 1 comments

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

zy1075984 avatar Jul 11 '23 12:07 zy1075984

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.

maxkatz6 avatar Jul 11 '23 23:07 maxkatz6

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.

I4-PJ avatar Oct 17 '23 09:10 I4-PJ

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.

maxkatz6 avatar Oct 17 '23 23:10 maxkatz6