簡體   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