Blazor server app HttpClient call to http time out

45 Views Asked by At

Request to http: server from my Blazor server Azure-hosted app results in a timeout.

Request to https: server works.

Requests from browser work if sent to the http resource, and fail (blocked) if sent from https.

How I understood there is a same mixed content issue in my app. How do I bypass this? Is it possible?

API server I need to send requests does not accept https.

Many thanks!

public static async Task<HttpResponseMessage> GetVersion()
{
    var client = new HttpClient 
                     {
                         BaseAddress = new Uri("http://webservice....")
                     };

    var getVersion = new Version();

    HttpResponseMessage response = await client.PostAsJsonAsync("", getVersion);
    response.EnsureSuccessStatusCode();

    return response;
}

Searching on the internet gives some perception that this is not going to be possible.

1

There are 1 best solutions below

1
Jurij.S On

Looks like it was not the mixed content issues. Strangely sorted it by using PostAsync method instead os PostAsJsonAsync. Following works without any issues.

using System.Text;
public static async Task<string> GetVersion()
    {
        var client = new HttpClient();

        var getVersion = new Version();
        string json = "{\""+"getVersion"+"\": {}}";
        var requestData = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PostAsync(
            "http://webservice....", requestData);
        response.EnsureSuccessStatusCode();

        return await response.Content.ReadAsStringAsync();
    }