0

I'm trying to connect to our wordpress api in our asp.net mvc application, using the following code

 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;

    }

however I'm getting the following exception :

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.

If I access this feed from a browser, it works fine https://lifespeak.com/wp-json/wp/v2/posts?categories=6

However, if I try from fiddler, I get the same exception: please see fiddler image

I'm assuming that something on our wordpress site is blocking this request for some reason. Is there something I can configure to prevent this? How can I determine the cause?

Daryl1976
  • 675
  • 2
  • 8
  • 20
  • 1
    Possible duplicate of [Fiddler 4.6 cannot connect to strong SSL?](https://stackoverflow.com/questions/44141255/fiddler-4-6-cannot-connect-to-strong-ssl) – dave May 24 '18 at 21:57
  • yes thank you, it looks like this is the issue with fiddler - I suspect it's the issue with the application as well. Will check and confirm – Daryl1976 May 24 '18 at 23:42

1 Answers1

0

The issue was that the version of System.Net I was using in my application was attempting to make the request to the wordpress API using TLS 1.0, and was getting rejected, similar to the issue with fiddler that dave pointed out above. I fixed this by adding the following line of code in the method, as specified in How to specify SSL protocol to use for WebClient class

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

Note that the value has to be added manually and cast as a SecurityProtocolType, as .net 4.0 (the version I was using) doesn't support tls1.2

Daryl1976
  • 675
  • 2
  • 8
  • 20