我的应用程序以前使用的是.net 3.5,但后来我将其升级到4.8。
我添加以下代码以支持安全性:
ServicePointManager.SecurityProtocol|= SecurityProtocolType.SystemDefault|
SecurityProtocolType.Ssl3 |
SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls13;
HttpWebRequest req = WebRequest.Create(HelpURL + path) as HttpWebRequest;
req.UseDefaultCredentials = true;
req.PreAuthenticate = true;
req.Credentials = CredentialCache.DefaultCredentials;
var statusCode = ((HttpWebResponse)req.GetResponse()).StatusCode;
它适用于https,但不适用于http!
The requested security protocol is not supported
如何允许使用http?
解决方案:
protected void Page_Load(object sender, EventArgs e)
{
try
{
Uri validatedUri = null;
var result = Uri.TryCreate(_path, UriKind.RelativeOrAbsolute, out validatedUri);
if (result)
{
HelpURL = path;
if(HelpURL.StartsWith("https://"))
{
ServicePointManager.SecurityProtocol |= SecurityProtocolType.SystemDefault |
SecurityProtocolType.Ssl3 |
SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls13;
}
}
}