我的错误是 该请求已中止:无法创建SSL / TLS安全通道。 我正在使用Avaya office management api文档中的示例代码。 我无法获取CertificateValidationCallback进行编译。
受保护的无效Page_Load(对象发送者,EventArgs e) {
ServicePointManager.ServerCertificateValidationCallback = new
System.Net.Security.RemoteCertificateValidationCallback(CertificateValidationCallback);
String username = "";
String password = "";
String url = "https://10.207.251.41:7070/WebManagement/ws/sdk/security/authenticate";
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
request.Method = "GET";
request.ContentType = "application/json";
request.Headers.Add("X-User-Client", "Avaya-WebAdmin");
request.Headers.Add("X-User-Agent", "Avaya-SDKUser");
String credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password));
request.Headers.Add("Authorization", "Basic " + credentials);
request.CookieContainer = cookieContainer;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var resStream = response.GetResponseStream();
var reader = new StreamReader(resStream);
String responseContent = reader.ReadToEnd();
response.Close();
}
答案 0 :(得分:1)
如果证书不受证书颁发机构的信任(我不认为是由于请求而引起的,但听起来像是测试证书),则应以MMC控制台信任的方式将其安装在系统上,并添加“证书”管理单元,选择本地PC作为目的地。然后,在管理单元中将出现一个证书文件夹列表,找到“受信任的根证书”并导入证书(如果没有,我认为您可以使用浏览器访问链接{{3 }})。在此安装后,就可以解决您的问题