0

我正在尝试从 https url 读取 xml 文件

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
using(WebClient client = new WebClient()) {
   contents = client.DownloadString(dr["XmlImpotURL"].ToString() + dr["ApiKey"].ToString());
}

我收到这个错误

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

我花了大约 2 个小时来解决这个问题,但我似乎找不到任何解决方案。

4

2 回答 2

0

这已解决,而不是

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;

我用了

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;

现在它正在工作,谢谢大家的回答。

于 2013-10-23T00:43:58.287 回答
0

尝试这个

        string sVal = "http://www.w3schools.com/xml/note.xml";
        XDocument document = XDocument.Load(sVal);

或者

   Uri url = new Uri("http://www.w3schools.com/xml/note.xml");
        using (var wc = new WebClient())
        {
            string sss =  wc.DownloadString(url);
        }

如果您面临安全问题

尝试这个

  HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    req.Method = "GET";
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;


    // allows for validation of SSL conversations
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


    WebResponse respon = req.GetResponse();
    Stream res = respon.GetResponseStream();

    string ret = "";
    byte[] buffer = new byte[1048];
    int read = 0;
    while ((read = res.Read(buffer, 0, buffer.Length)) > 0)
    {
        Console.Write(Encoding.ASCII.GetString(buffer, 0, read));
        ret += Encoding.ASCII.GetString(buffer, 0, read);
    }
    return ret;

或者

 private void Test()
 {    ServicePointManager.ServerCertificateValidationCallback += new                       
      RemoteCertificateValidationCallback(Certificate);
  }

 private static bool Certificate(object sender, X509Certificate certificate,  
                             X509Chain chain, SslPolicyErrors  policyErrors) {
                           return true;
                       }

检查此链接以获取更多信息http://blogs.msdn.com/b/dgorti/archive/2005/09/18/471003.aspx

于 2013-10-22T04:46:38.947 回答