首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

程序请求网站时?报“基础连接已经关闭: 发送时发生异常。 -> System.IO.IOException: 由于远程方已关闭传输流,身份验证失败。”求解

2012-04-24 
程序请求网站时?报“基础连接已经关闭: 发送时发生错误。 --- System.IO.IOException: 由于远程方已关闭传

程序请求网站时?报“基础连接已经关闭: 发送时发生错误。 ---> System.IO.IOException: 由于远程方已关闭传输流,身份验证失败。”求解
string url = "https://data.cathaylife.cn/servlet/HttpDispatcher/KAA0_0100/prompt?newTxRequest=true&syscode=DA&subcode=KAA0";

  HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(login_url);

  myRequest.Method = "GET";

  HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();


最后一句执行过了报:“基础连接已经关闭: 发送时发生错误。 ---> System.IO.IOException: 由于远程方已关闭传输流,身份验证失败。”,浏

览器是可以访问并能看到源码的。但是程序就不行。求解。各位大虾,帮忙一下。

[解决办法]
这样即可

C# code
string url = "https://data.cathaylife.cn/servlet/HttpDispatcher/KAA0_0100/prompt?newTxRequest=true&syscode=DA&subcode=KAA0";    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);    myRequest.Method = "GET";myRequest.Proxy = null;myRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0";myRequest.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.8,zh-hk;q=0.6,ja;q=0.4,zh;q=0.2");myRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();MessageBox.Show(new System.IO.StreamReader(myResponse.GetResponseStream(),Encoding.GetEncoding("GB2312")).ReadToEnd()); 

热点排行