0

这在 http 上运行良好,但在 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];
    }
4

1 回答 1

2

它可能是 SSL 证书问题,您将通过 WebClient 或 WebRequest 访问 SSL 看到这一点,具体取决于您的证书颁发者的情况。有关如何解决此问题的详细信息,请参阅此先前的问题。

于 2012-11-19T17:58:41.737 回答