【问题标题】:Wordpress api not allowing rejecting server-side connectionWordpress api 不允许拒绝服务器端连接
【发布时间】:2018-11-04 05:04:41
【问题描述】:

我正在尝试使用以下代码在我们的 asp.net mvc 应用程序中连接到我们的 wordpress api

 public static string GetLifespeakBlogListings()
    {
      WebClient client = new WebClient();
      string url = "https://lifespeak.com/wp-json/wp/v2/posts?categories=6";
      string listings = client.DownloadString(url);

      return listings;

    }

但是我得到以下异常:

System.Security.SecurityException Failed to negotiate HTTPS connection with server.fiddler.network.https> HTTPS handshake to lifespeak.com (for #1) failed. System.IO.IOException Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

如果我从浏览器访问此提要,它可以正常工作https://lifespeak.com/wp-json/wp/v2/posts?categories=6

但是,如果我从提琴手尝试,我会得到同样的异常:

我假设我们的 wordpress 网站上的某些内容由于某种原因阻止了此请求。我可以配置什么来防止这种情况发生吗?如何确定原因?

【问题讨论】:

标签: asp.net wordpress system.net


【解决方案1】:

问题是我在应用程序中使用的 System.Net 版本试图使用 TLS 1.0 向 wordpress API 发出请求,但被拒绝,类似于 dave 上面指出的提琴手问题。我通过在方法中添加以下代码行来解决此问题,如How to specify SSL protocol to use for WebClient class 中指定的那样

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

请注意,该值必须手动添加并转换为 SecurityProtocolType,因为 .net 4.0(我使用的版本)不支持 tls1.2

【讨论】:

    猜你喜欢
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多