问题描述
在调用PC时禁用密码“ TLS_RSA_WITH_AES_128_CBC_SHA”时,无法使用.net应用程序调用https API。
但是可以通过邮递员打电话
static void Main(string[] args)
{
System.Net.ServicePointManager.SecurityProtocol =
System.Net.SecurityProtocolType.Tls
| System.Net.SecurityProtocolType.Tls11
| System.Net.SecurityProtocolType.Tls12;
var handler = new httpclienthandler()
{
UseDefaultCredentials = true
};
System.Net.ServicePointManager.Expect100Continue = false;
HttpClient httpClient = new HttpClient(handler);
httpClient.BaseAddress = new Uri("urlbaseaddress");
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
try
{
var datareq = new StringContent("data",Encoding.UTF8,"text/plain");
var response = httpClient.PostAsync("xyz/Service1.svc/sts",datareq);
}
catch (HttpRequestException ex)
{
Console.WriteLine(ex.ToString());
}
}
错误:
System.AggregateException:发生一个或多个错误。 ---> System.Net.Http.HttpRequestException:发送时发生错误 请求。 ---> System.Net.WebException:基础连接 已关闭:发送时发生意外错误。 ---> System.IO.IOException:无法从传输读取数据 连接:远程强行关闭了现有连接 主办。 ---> System.Net.sockets.socketException:现有连接 被远程主机强行关闭
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)