程序請(qǐng)求網(wǎng)站時(shí):基礎(chǔ)連接已經(jīng)關(guān)閉: 發(fā)送時(shí)發(fā)生異常

字號(hào):


    程序請(qǐng)求網(wǎng)站時(shí)?報(bào)“基礎(chǔ)連接已經(jīng)關(guān)閉: 發(fā)送時(shí)發(fā)生錯(cuò)誤。 ---> System.IO.IOException: 由于遠(yuǎn)程方已關(guān)閉傳輸流,身份驗(yàn)證失敗?!鼻蠼?BR>    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();
    最后一句執(zhí)行過(guò)了報(bào):“基礎(chǔ)連接已經(jīng)關(guān)閉: 發(fā)送時(shí)發(fā)生錯(cuò)誤。 ---> System.IO.IOException: 由于遠(yuǎn)程方已關(guān)閉傳輸流,身份驗(yàn)證失敗?!保瑸g
    覽器是可以訪問并能看到源碼的。但是程序就不行。求解。各位大蝦,幫忙一下。
    ------解決方案--------------------
    這樣即可
    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());