0

This worked well on http, but doesn't work on https.

private Cookie GetAuthCookie(string user, string pass)
    {
        var http = WebRequest.Create(_baseUrl+"Users/Login") as HttpWebRequest;
        http.AllowAutoRedirect = false;
        http.Method = "POST";
        http.ContentType = "application/x-www-form-urlencoded";
        http.CookieContainer = new CookieContainer();
        var postData = "UserName=" + user + "&Password=" + pass + "&RememberMe=true&RememberMe=false&ReturnUrl=www.google.com";
        byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(postData);
        http.ContentLength = dataBytes.Length;
        using (var postStream = http.GetRequestStream())
        {
            postStream.Write(dataBytes, 0, dataBytes.Length);
        }
        var httpResponse = http.GetResponse() as HttpWebResponse;
        return httpResponse.Cookies[FormsAuthentication.FormsCookieName];
    }
iLemming
  • 34,477
  • 60
  • 195
  • 309
  • 1
    Its probably an SSL cert issue, see this question for details: http://stackoverflow.com/questions/560804/how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-using-https – curtisk Nov 19 '12 at 17:35
  • I'll make an answer version to close the loop on this question – curtisk Nov 19 '12 at 17:56

1 Answers1

2

Its probably an SSL cert issue, you'll see this with accessing SSL via WebClient or WebRequest depending on the situation with your certificate issuer. See this prior question for details on how to get around this.

Community
  • 1
  • 1
curtisk
  • 19,950
  • 4
  • 55
  • 71