I am trying to login to an https website , and when i run the code ,I dont get an error but im not logged in either, So i would like to know what is the problem I used the same code and technique for an http website (with different postdata string obviousely) and it logged me in here is the code:
string postData = "JAVASCRIPT_ON=userName=XXXX&password=XXX&loginAction=Logon";
CookieContainer tempCookies = new CookieContainer();
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteData = encoding.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://direct.gov.mb.ca/ppr/actions/loginDispatcher");
request.Method = "POST";
request.KeepAlive = true;
request.CookieContainer = tempCookies;
request.ContentType = "application/x-www-form-urlencoded";
request.Referer = "https://direct.gov.mb.ca/ppr/jsps/login/login.jsp";
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
request.ContentLength = postData.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(byteData, 0, byteData.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
tempCookies.Add(response.Cookies);
loginCookies = tempCookies;
您应该将所有请求的CookieContainer
属性设置为同一实例。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.