HTTP request from a url to HOLOLENS 2

22 views Asked by At

I'm trying to make an http request to a server, on unity it doesn't give errors but on hololens it doesn't work. It lags a lot but it doesn't work. In particular I'm trying to send a string in base 64 and then translate it back. Using a local server and an external Unity server doesn't cause any problems. However, it doesn't work in Hololens. Suggestions?

` 
 void Update()
 {
    chiamataIMAGE();
    System.Threading.Thread.Sleep(100);
 }
 // Decodifica la stringa da base64 a una Texture2D (la stringa rappresenta un'immagine)
 public Texture2D Decode(string input)
 {
    byte[] img = System.Convert.FromBase64String(input);
    Texture2D txt = new Texture2D(1, 1);
    txt.LoadImage(img);
    return txt;
 }
 // Inserisce la Texture2D in un nuovo materiale
 public Material MaterialWithTexture(Texture2D texture) {
    Material material = new Material(Shader.Find("Standard"));
    material.mainTexture = texture;
    return material;
 }
 async void chiamataIMAGE()
 {
        try
    {
        // Creo un'istanza di HttpClient
        using (HttpClient client = new HttpClient())
        {
            // Imposto l'indirizzo del server
            client.BaseAddress = new Uri("http://127.0.0.1:3000");

            // Creo un'istanza di HttpResponseMessage
            HttpResponseMessage response = new HttpResponseMessage();

            // Eseguo la chiamata GET
            response = await client.GetAsync("/immagine");

            // Leggo il contenuto della risposta
            string content = await response.Content.ReadAsStringAsync();

            // Applica il materiale con l'immagine all'imageQuad
            MeshRenderer quadRenderer = imageQuad.GetComponent<MeshRenderer>();
            if (quadRenderer == null)
            {
                Debug.LogError("Il GameObject deve avere un componente MeshRenderer.");
                return;
            }
            quadRenderer.material = MaterialWithTexture(Decode(content));
        }
    }
    catch (Exception e)
    {
             Debug.LogError("Errore durante la chiamata API: " + e.Message);
        }
    }
`
0

There are 0 answers