c# - 没有这样的主机已知 —> System.Net.Http.HttpRequestException :

标签 c# .net azure rest botframework

我正在开发机器人解决方案,其中我正在进行 REST 调用以从其他服务器获取一些详细信息。

在本地主机中,我的代码工作正常,但在 Azure 中发布代码后,我收到以下错误:

System.Net.WebException: No such host is known No such host is known —> System.Net.Http.HttpRequestException: No such host is known —> System.Net.Sockets.SocketException: No such host is known

我正在使用 HttpWebRequest 选项。

我可以知道是什么原因吗?

最佳答案

我不确定下面的解决方案是否适合您,但看起来该解决方案值得检查。这是一个可能包含有用信息的答案。看看这个答案并相应地检查您的解决方案:

问题描述:

I deployed a .NET Windows Service on Azure Virtual Machine running Windows Server with an opened port that allow me to connect to it, this service is like a server using socket. The problem is that when I try to connect from my PC to that hosted server it doesn't work and I get this exception: System.Net.Sockets.SocketException: 'No such host is known'. The port is opened and visible from my PC. Can someone tell me why I get that exception? If I run locally all works ok.

答案:

The Exception seems to be a DNS issue. I am not familiar with C#, from networking, you could check the followings on your side:

  1. Windows service is running and the port is listening on the Azure VM.

  2. The port is allowed for outbound traffic from your PC and Inbound traffic on your Azure VM. Check the VM firewall settings on both sides between your PC and Azure VM. Also, you could check the NSG settings follow this. You could use telnet vmpublicIP port on your PC CMD to verify network connectivity.

  3. Verify your PC can resolve the address of the hosted server if you connect it via its DNS name. You could use the NSlookup or DIG to verify this. If it's DNS issue, you also could add a line in hosts file (located in %WINDIR%\system32\drivers\etc on windows) mapping the hosted server's IP to a name. Hope this helps.

.NET Service System.Net.Sockets.SocketException: 'No such host is known'

关于c# - 没有这样的主机已知 —> System.Net.Http.HttpRequestException :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56852702/

相关文章:

c# - 单元测试 ASP.NET Core HttpResponse.OnStarting()

c# - 在 C# 中实现链式事件的最佳方式是什么

c# - 有没有办法使用币安 API 获取代币的市值或市值排名?

c# - 我应该使用什么而不是 session ?

android - 从 Android 连接到 Azure DocumentDB

c# - 我现在应该为此目的使用抽象基类吗?

c# 序列化 - 包含具有属性的简单内容的复杂类型

c# - 十进制值舍入 .99

azure - 如何升级 Azure Databricks 中的 Hive 版本

azure - Azure Application Insights 与 Google 搜索之间的 IP 地址不匹配