PostAsJasonAsync returns 502 Bad Gateway in Maui Blazor Hybrid app, but not in postman or in Blazor WebAsembly

88 Views Asked by At

I have two apps, that share code for posting with httpclient.PostAsJasonAsync in a common Razor library. One is a Blazor WebAssembly and the other is a Maui Blazor Hybrid app.

In the Blazor Web assembly app, PostAsJasonAsync works as expected, and a new record i created in the database.

In the MAUI Blazor hybrid app, the same shared code returns 502 Bad Gateway. Does not matter whether I run i as a Windows App or a Android app.

In Postman everything is fine.

Anyone having a clue to what could cause this?

I can add that this older code works:

string json = JsonSerializer.Serialize<T>(element);
StringContent strc = new StringContent(json, Encoding.UTF8, "application/json");
sResponse = await Http!.PostAsync(sURI, strc);

while this one do not:

sResponse = await Http!.PostAsJsonAsync<T>(sURI, element);
0

There are 0 best solutions below