[英]Azure web app - “HttpClient Unable to connect to the remote server”
I'm trying to make a request using HttpClient
in my azure web app but I get the error: Unable to connect to the remote server
我试图在我的azure Web应用程序中使用HttpClient
发出请求,但出现错误: Unable to connect to the remote server
If I open the kudu console I can successfully make the request using: 如果打开kudu控制台,则可以使用以下命令成功发出请求:
Invoke-RestMethod -Uri https://mydomain/myendpoint
When I run the program locally it works. 当我在本地运行程序时,它可以工作。
When I run the program inside an azure web app it does not work. 当我在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);
Update 1: 更新1:
I tried setting: 我尝试设置:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
but it had no effect. 但没有效果。
You can not make direct call to your on=premise service from Azure Web App. 您无法从Azure Web App直接调用on = premise服务。 You need Hybrid Connection Manager for this purpose. 为此,您需要混合连接管理器。 Look at below post: 看下面的帖子:
Azure web app service to call onpremise WEB API using HttpClient using hybrid connection manager Azure Web应用程序服务使用混合连接管理器使用HttpClient调用本地WEB API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.