如何从 Azure 应用服务连接到非标准端口上的外部服务?

How to connect to an external service on a non-standard port from an Azure App Service?

我正在尝试从 Azure App Services 访问第三方服务(最好是 Functions,但 Web App 也可以)。但是,此服务托管在非标准端口上,例如https://myservice.com:445

我正在使用 System.Net.Http.HttpClient 发出 POST 请求,但始终收到 SocketException:

An error occurred while sending the request. Unable to connect to the remote server An attempt was made to access a socket in a way forbidden by its access permissions 1.2.3.4:445

该代码适用于我的本地环境(Functions 模拟器或 Kestrel),但在 Azure 上失败。我尝试使用托管在常规 https 端点上的服务,例如https://myotherservice.com,通话正常。

我假设有某种出站防火墙规则阻止了第一次调用,但我还没有找到任何配置选项来禁用它。可能吗?不幸的是,我无法更改我需要调用的服务的端点。

在检查您的申请后,我确实发现那些传出请求被基础设施阻止了。

我还能够在此处找到涵盖这些端口的 public 文档: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#restricted-outgoing-ports