1

I am facing this error sometimes while I am trying to connect to the server using WebClient.

However I have gone through the previous questions and answers such as Getting EOF exception over https call about this. I have already tried their solutions but that didn't help me.

As per previous questions, I've also updated .net framework from 4.5 to 4.6.1 but still facing the same.

My code is like below

    private static string GetWebContent(string url)
    {
        string response = null;
        try
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;                
            using (var request = new GZipWebClient())
            {
                response = request.DownloadString(url);
                request.Dispose();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return response;
    }
Pinki
  • 71
  • 1
  • 10
  • Possible duplicate of [Getting EOF exception over https call](https://stackoverflow.com/questions/5382548/getting-eof-exception-over-https-call) – Ian Kemp Dec 27 '18 at 14:12
  • Yes probably. due to shortage of reputation i can't comment on that question. I have already tried that solution but that didn't solve my problem. – Pinki Jan 02 '19 at 07:09

1 Answers1

1

Somehow your code is trying to use TLS but the server to which you are sending request does not support it.

You can try setting SSL3 explicitly

Change:

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

To:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37
  • 1
    Thanks for your answer. I have tried this but still It is causing issue regarding TLS such as "The request was aborted: Could not create SSL/TLS secure channel.". – Pinki Dec 28 '18 at 07:15