繁体   English   中英

Azure Web应用程序-“ HttpClient无法连接到远程服务器”

[英]Azure web app - “HttpClient Unable to connect to the remote server”

我试图在我的azure Web应用程序中使用HttpClient发出请求,但出现错误: Unable to connect to the remote server

如果打开kudu控制台,则可以使用以下命令成功发出请求:

Invoke-RestMethod -Uri https://mydomain/myendpoint

当我在本地运行程序时,它可以工作。

当我在azure Web应用程序中运行程序时,它不起作用。

HttpClient _client;        

public MyHttpClient() {
  _client = new HttpClient();
  _client.BaseAddress = new System.Uri(ConfigurationManager.AppSettings["MyUri"]);          
  _client.DefaultRequestHeaders.Accept.Clear();            
  _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));        }

//...

  var path = "/myendpoint";
  var data = new Dictionary<string, string>();        
  data.Add("param1", value);        
  var response = await _client.PostAsJsonAsync(path, data);

更新1:

我尝试设置:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | 
SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;

但没有效果。

您无法从Azure Web App直接调用on = premise服务。 为此,您需要混合连接管理器。 看下面的帖子:

Azure Web应用程序服务使用混合连接管理器使用HttpClient调用本地WEB API

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM