Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can't connect to https page

Can't connect to https page

Scheduled Pinned Locked Moved C#
securityhelpcsharpdotnetalgorithms
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mostafa Siraj
    wrote on last edited by
    #1

    Hello, I'm trying to access an https page, I don't know why .NET doesn't allow it here is the error I got "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." and when I try to override ServicePointManager.ServerCertificateValidationCallback with this function

    public static bool ValidateServerCertificate(
    object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors)
    {
    return true;
    }

    I got time out exception. here is a snippet of my code

        ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);
        CookieContainer c = new CookieContainer();
    
        reqLogin = (HttpWebRequest)WebRequest.Create(url);
        reqLogin.Method = "POST";
        reqLogin.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3)     Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729)";
        
        reqLogin.ContentType = "application/x-www-form-urlencoded";
        reqLogin.KeepAlive = true;
        reqLogin.CookieContainer = new CookieContainer();
        reqLogin.CookieContainer = c;
        //reqLogin.CookieContainer.Add(col1);
        reqLogin.AllowAutoRedirect = true;
        reqLogin.UseDefaultCredentials = true;
        reqLogin.Timeout = 5000;                     
    
        using (StreamWriter sendingData = new
            StreamWriter(reqLogin.GetRequestStream()))
        {
            sendingData.Write(postMessage);
            sendingData.Flush();
            sendingData.Close();
        }
    
        resLogin = (HttpWebResponse)reqLogin.GetResponse();
    

    I'm sure that you faced that problem before, i'm searching about a solution for this problem from 4 hours and couldn't find any solution, I really hope that you can help me Thanks in Advance.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups