Before starting, I know I can use the UnityWebRequest class instead. The problem is that it is another library the one that is failing: NEthereum's source code, which makes heavy use of the HttpClient.
So I tried this in a behaviour (2021.3.25):
using System;
using System.Net.Http;
using UnityEngine;
public class SampleBehaviour : MonoBehaviour
{
public void Start()
{
TestHttp();
}
private async void TestHttp()
{
using var client = new HttpClient();
client.BaseAddress = new Uri("http://127.0.0.1:8545");
await client.GetAsync("/").ConfigureAwait(false);
}
}
(I tried other local addresses, like my LAN ones, considering that http server is attending on 0.0.0.0 and I succeed hitting it with cURL)
BUT when I try this, I get this exception:
SocketException: An address incompatible with the requested protocol was used
Now, the issue is that I use IPv4 in a daily basis in other places. What's wrong? Is it something in the .NET setup in the current Unity version? (I'm using .NET Framework and, again, 2021.3.25)
More context here:
I made this test in Unity:
And still get the error:
While a stand-alone .NET Framework console application does not fail like this:
And, more important: This HttpClient-related things were working before. This happened after moving to a newer version of Unity (the 2021.3.25 I'm using now). This is why I'm posting the question here and not in a pure C#-related site.
var contents = await response.Content.ReadAsStringAsync();
\$\endgroup\$