I have a .net core console app with a function that will do a simple http call and get the page content (this is for a testing). I am getting an issue "The SSL connection could not be established". But when I try the same url with Postman or a browser it works fine. Can anyone help me on this?
inner exception:"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.."
private static async Task<string> CallUrl(string url)
{
using var client = new HttpClient();
using var response = await client.GetAsync(url);
using var content = response.Content;
var data = await content.ReadAsStringAsync();
return data;
}
I tried the suggestion in The SSL connection could not be established as well. like this but no luck.
private static async Task<string> CallUrl(string url)
{
var clientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
return true;
}
};
using var client = new HttpClient(clientHandler);
using var response = await client.GetAsync(url);
using var content = response.Content;
var data = await content.ReadAsStringAsync();
return data;
}
我在调用 web 服务时遇到了同样的问题,我能够在 IIS AppPool 高级属性上修复更新“加载用户配置文件”= true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.