Pinging raspberrypi.local [192.168.1.104] with 32 bytes of data:
Reply from 192.168.1.104: bytes=32 time=16ms TTL=64
Однако при попытке достичь/разрешить raspberrypi.local хост с использованием API .NET API,
API, которые проваливаются
- TcpClient.Connect("raspberrypi.local", myPort)
- dns.gethostaddresses
Вопреки этому, apis, которые выполняют работу :
/>[*]dns.gethostentry -> Возвращает две записи (IPv4 и IPv6) с правильными адресами < /li>
HttpClient может завершить запрос
Ping (new Ping().Send(host, 10_000)< /code>) достигает хоста < /li>
< /ul>
Почему TcpClient не может разрешить хост, в то время как httpclient делает? Ссылка: < /p>
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Security.Cryptography;
const string host = "raspberrypi.local";
RunTest("OS supports ipv6", () => System.Net.Sockets.Socket.OSSupportsIPv6);
// -> true
RunTest("GetHostEntry", () => Dns.GetHostEntry(host));
// -> returned AddressList has 2 entries
RunTest("GetHostAddresses", () => Dns.GetHostAddresses(host));
// -> SocketException 0x00002AF9
RunTest("Ping", () => new Ping().Send(host, 10_000));
// -> proper PingReply
RunTest("TcpClient", () =>
{
using var tcp = new TcpClient();
tcp.Connect(host, 10_001);
return tcp.Connected;
});
// -> SocketException 0x00002AF9
RunTest("HttpClient", () =>
{
using var http = new HttpClient(new HttpClientHandler(){
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
});
return http.GetStringAsync($"https://{host}/").ConfigureAwait(false).GetAwaiter().GetResult().Contains("");
});
// -> true
static void RunTest(string name, Func action)
{
try
{
Console.WriteLine($"Result of {name}:");
action().Dump();
}
catch (Exception ex)
{
Console.WriteLine($"Failed: {ex}");
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... s-net-apis