title: How do I login to a website programmatically when it crosses over from HTTPS to HTTP?
body: <p>An example site is: <a href="http://www.dotmed.com" rel="nofollow noreferrer">http://www.dotmed.com</a>. The login page is at: <a href="https://secure.dotmed.com/login.html" rel="nofollow noreferrer">https://secure.dotmed.com/login.html</a> (Secured by SSL HTTPS). When you authenticate, you get redirected to: <a href="http://www.dotmed.com/index.html" rel="nofollow noreferrer">http://www.dotmed.com/index.html</a> (Not secured by SSL). </p>
  
  <p>I am using code from previous posts, but the "session" doesn't seem to persist across requests. Maybe this has something to do with the cookies being set in one domain and trying to access a page in another domain? Not sure.</p>
  
  <pre><code>    public static void Login()
      {
          try
          {
              CookieAwareWebClient client = new CookieAwareWebClient();
              client.BaseAddress = "https://secure.dotmed.com/";
  
              // Do a simple GET on the Login page first (It sets cookies)
              string source = client.DownloadString("login.html");
  
              // Attempt a POST to the Login page
              NameValueCollection loginData = new NameValueCollection();
              loginData.Add("refer", "");
              loginData.Add("backfromssl", "1");
              loginData.Add("user", "*****************");
              loginData.Add("pass", "*********");           
              byte[] ret = client.UploadValues(LOGIN_PAGE, "POST", loginData);
              string pageSource = Encoding.ASCII.GetString(ret);       // I can see the user is logged in successfully here
  
              // Now you are logged in and can request pages
              client.BaseAddress = "http://www.dotmed.com";            // ???????????????
              string htmlSource = client.DownloadString("index.html"); // ???????????????
          }
          catch { }
      }
  </code></pre>
  
  <p>My CookieAwareWebClient class is pulled directly from: <a href="https://stackoverflow.com/a/14907201/787794">https://stackoverflow.com/a/14907201/787794</a></p>
  
  <p>When I try the client.DownloadString() method with the question marks next to it, it returns a page where the user is not logged in. How can I make the authentication stick across requests?</p>