【发布时间】:2019-10-15 09:57:45
【问题描述】:
我有一个 .NET Core 控制器 API。
通过安全链接(即 https:///api/values)访问 Web 方法时,它不起作用
如果我使用不安全的链接访问它,即 http:///api/values,它工作正常。
如果我需要在我的 Startup.cs 或 appsettings.json 中做点什么,请告诉我
访问 API 的示例代码:
try
{
string serviceUrl= "https://domainname/api/values";
HttpClient client = new HttpClient();
HttpResponseMessage response = client.GetAsync(serviceUrl).Result;
string stringData = response.Content.ReadAsStringAsync().Result;
}
catch (Exception ex)
{
throw ex;
}
【问题讨论】:
-
it's not working是什么意思? -
您好 Chetan,感谢您的回复。尝试访问它时抛出异常。消息:底层连接已关闭:发送时发生意外错误。无法从传输连接读取数据:现有连接被远程主机强行关闭。问候,Ashish
-
您是否使用
IIS在本地浏览您的代码?因为如果是这样,那么http是有道理的。 -
写
System.Net.ServicePointManager.SecurityProtocol作为try块的第一行 -
我在 Azure 上发布我的代码。发布后,如果我使我的应用程序安全,即 https - 当我尝试访问它时(通过客户端应用程序。在我的情况下,它是 VSTO 插件),抛出异常。 - 如果我没有保护应用程序/站点并访问它,它就可以工作。
标签: c# .net rest api .net-core