遠程服務器返回錯誤 (401) 未經授權 解決方案


沒有權限 設置權限

WebClient client=new WebClient();
//NetworkCredential credentials = new NetworkCredential("名字", "密碼");
//client.Credentials = credentials;

 

未能為 SSL/TLS 安全通道建立信任的解決辦法
最簡單的辦法是:

1,先加入命名空間:

using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;

2,再重載CheckValidationResult方法,返回true

public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // 總是接受
     return true;
}

3,然后在HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);前面加上如下一行代碼:

ServicePointManager.ServerCertificatidationCallback = new System.Net.Security.RemoteCertificatidationCallback(CheckValidationResult);//驗證服務器證書回調自動驗證


//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM