关于使用OpenContactsNet导入MSN联系人的问题"基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系"

zhangqy 2009-02-24 01:56:16
在使用OpenContactsNet导入MSN联系人时,报基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。郁闷了好久,请高人指点,不胜感谢!
部分代码如下:

UriBuilder urib = new UriBuilder();
urib.Scheme = "HTTPS";
urib.Path = string.Format( "/{0}/LiveContacts", credential.UserName );
urib.Host = "cumulus.services.live.com";
urib.Port = 443;
HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( urib.Uri );
string authHeader = string.Format( "WLID1.0 t=\"{0}\"", ticket );
request.Headers.Add( "Authorization", authHeader );
WebResponse response = request.GetResponse();//这句就报以上的错误:"基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系"
...全文
1038 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunshinesjw 2010-07-19
  • 打赏
  • 举报
回复
不行啊!报错:服务法连接到服务器!
chinarenkai 2009-12-18
  • 打赏
  • 举报
回复
还是有问题。。这个东西报错了!
lov1986 2009-07-22
  • 打赏
  • 举报
回复
哈哈 谢谢分享了
Teng_s2000 2009-03-06
  • 打赏
  • 举报
回复
UP
wangping_li 2009-03-06
  • 打赏
  • 举报
回复
看看:


private void button6_Click(object sender, EventArgs e)//下载数据文件
{
string downloadAdd = "https://scm.auchan.com.cn/php/scm_items_stat_download.php?sup_no=au&code=all";
string saveFile = "d:\\a.xls";
if (downfile(downloadAdd, saveFile))
{
MessageBox.Show("下载完毕!");
}
else
{
MessageBox.Show("下载过程中出现错误:");
}
}
public bool downfile(string url, string LocalPath)
{
try
{
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
Uri u = new Uri(url);
HttpWebRequest mRequest = (HttpWebRequest)WebRequest.Create(u);
mRequest.Method = "GET";
mRequest.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse wr = (HttpWebResponse)mRequest.GetResponse();
Stream sIn = wr.GetResponseStream();
FileStream fs = new FileStream(LocalPath, FileMode.Create, FileAccess.Write);
long length = wr.ContentLength;
long i = 0;
while (i < length)
{
byte[] buffer = new byte[1024];
i += sIn.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, buffer.Length);
}
sIn.Close();
wr.Close();
fs.Close();
return true;
}
catch (WebException exp)
{
MessageBox.Show(exp.Message, "error");
return false;
}

}
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // Always accept
return true;
}
命名空间加上
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
Terry717 2009-03-04
  • 打赏
  • 举报
回复
帮顶!!!
cxty 2009-03-03
  • 打赏
  • 举报
回复
HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( urib.Uri );
上加行
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);

然后再加两个函数
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // Always accept
return true;
}
public bool CheckValidationResult(ServicePoint sPoint, System.Security.Cryptography.X509Certificates.X509Certificate cert, WebRequest wRequest, int certProb)
{
// Always accept
return true;
}

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧