c# - XmlDocument.Load : Could not create SSL/TLS secure channel

标签 c# .net ssl httpwebrequest xmldocument

我的应用程序中散布着与此类似的简单代码:

new XmlDocument().Load("https://mybookingpal.com/xml/rest/product/organization/5?pos=" + "a3a2e74b809e0e87");

以上为新域名,旧域名为:

new XmlDocument().Load("https://razor-cloud.com/xml/rest/product/organization/5?pos=" + "a3a2e74b809e0e87");

您可以尝试这两个 URL,看看它们工作正常/产生相同的 XML 结果。

SSL 中可能发生了某些变化,导致 .Load() 无法运行。我有两个问题:

  1. 是什么导致了失败,所以我可以尝试在一个地方(在 API 服务器上)修复它?
  2. 如何修复客户端代码?

最佳答案

我也遇到了同样的问题。事实证明这是由

中定义的 xml DTD 引起的
<!DOCTYPE>

检查xml文件头

<!DOCTYPE xxx SYSTEM "url">

复制 URL 并粘贴到浏览器中,然后运行 ​​Fiddler 以查看它正在使用什么协议(protocol)。

我的情况是,我正在运行本地服务器来解析使用来自第 3 方的 DTD 的 xml 文件。我的本地服务器在 Tls11 或 Tls12 上运行,而第 3 方 DTD(url)只能通过 Ssl 或 Tls10 进行通信。所以握手失败。

我的解决方案很简单,只需添加以下行作为临时修复:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;

关于c# - XmlDocument.Load : Could not create SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26650174/

相关文章:

c# - Linq 到 XML : Get all nodes that contain certain children

c# - 对 MVC Controller 感到好奇吗?

java - Jboss 4.2.3 迁移到 Jboss 7 EAP、数据源和安全

java - Jenkins 2.121.1 使用 TLS 1.0

c# - 如果使用接口(interface),类是否应该始终严格实现接口(interface)

c# - System.Data.SQLite 锁/共享冲突

c# - 如何按键对字典进行排序

c# - 使用SimpleInjector基于泛型参数条件注册装饰器

c# - WCF HttpTransport : streamed vs buffered TransferMode

php - Curl - 无法使用 p12 证书连接