1 Public voidLOGIN58 (stringNamestringpass)2 {3HttpWebRequest request = (HttpWebRequest) webrequest.create ("https://passport.58.com/login/");4Request. Method="GET";5Request. Cookiecontainer =NewCookiecontainer ();6HttpWebResponse response =(HttpWebResponse) request. GetResponse ();7 using(StreamReader str=NewStreamReader (response. GetResponseStream ()))8 {9HTML =Str. ReadToEnd ();Ten } OneCC =Response. Cookies; AMatch m = regex.match (HTML,"<input\\stype=\ "hidden\" \\sname=\ "path\" \\svalue=\ "(? <path>[^\"]+) \ "/>", Regexoptions.multiline |regexoptions.ignorecase); - stringPath = Httputility.urlencode (m.groups["Path"]. Value); - stringP1; the stringP2; - stringP3; -m = Regex.match (HTML,"var\\stimespan\\s=\\s (? <timespan>\\d+) \\s-\\snew", Regexoptions.multiline |regexoptions.ignorecase); - LongTimeSpan =Long. Parse (m.groups["TimeSpan"]. Value); +TimeSpan = TimeSpan-Long. Parse (WB1. Invokescript ("GetDateTime"). ToString ())-60000;//assume that the login page was loaded 1 minutes ago - + LongTimesign =Long. Parse (WB1. Invokescript ("GetDateTime"). ToString ()) +TimeSpan; ATimesign =1411094409520; atP1 = wb1. Invokescript ("GETP1",New Object[]{pass,timesign}]. ToString (); -P2 = wb1. Invokescript ("GETP2",New Object[] {pass, timesign}). ToString (); -P3 = wb1. Invokescript ("GETP3",New Object[] {pass, timesign}). ToString (); -m = Regex.match (HTML,"<input\\stype=\ "hidden\" \\sid=\ "Ptk\" \\sname=\ "Ptk\" \\sid=\ "Ptk\" \\svalue=\ "(? <ptk>[^\"]+) \ "/ >", Regexoptions.ignorecase |regexoptions.multiline); - - stringPTK = m.groups["PTK"]. Value; in -m = Regex.match (HTML,"<input\\stype=\ "hidden\" \\sid=\ "cd\" \\sname=\ "cd\" \\sid=\ "cd\" \\svalue=\ "(? <cd>[^\"]+) \ "/> ", Regexoptions.ignorecase |regexoptions.multiline); to stringcd = m.groups["CD"]. Value; + - stringUsername =Httputility.urlencode (name); the * stringPoststr =string. Format ("isweak=0&path={0}&p1={1}&p2={2}&p3={3}×ign={4}&ptk={5}&cd={6}& username={7}&password=password&remember=on&mcresult=undefined", Path, p1, P2,p3,timesign, PTK, CD, username); $ Panax Notoginseng stringPostURL ="Https://passport.58.com/dounionlogin"; - theHttpWebRequest Postrequest =(HttpWebRequest) webrequest.create (posturl); +Postrequest.method ="POST"; APostrequest.referer ="https://passport.58.com/login/"; thePostrequest.contenttype ="application/x-www-form-urlencoded"; +Postrequest.cookiecontainer =NewCookiecontainer (); - postRequest.CookieContainer.Add (cc); $ $ byte[] Postbytes =Encoding.UTF8.GetBytes (POSTSTR); - using(Stream Postdatastream =Postrequest.getrequeststream ()) - { thePostdatastream.write (Postbytes,0, postbytes.length); - }WuyiHttpWebResponse response1 =(HttpWebResponse) postrequest.getresponse (); the - using(StreamReader sr =NewStreamReader (response1. GetResponseStream ())) Wu { -HTML =Sr. ReadToEnd (); About } $m = Regex.match (HTML,"(? <num>\\d+) \ "", Regexoptions.multiline |regexoptions.ignorecase); - stringnum = m.groups["Num"]. Value; - stringcookies = response1. headers["Set-cookie"]; - AMatch m_www58com = Regex.match (cookies,"(? <g_58com>www58com=\ ". *?\")", Regexoptions.multiline |regexoptions.ignorecase); +Match m_58cooper = Regex.match (cookies,"(? <g_58cooper>58cooper=\ ". *?\")", Regexoptions.multiline |regexoptions.ignorecase); theMatch M_ppu = Regex.match (cookies,"(? <ppu>ppu=\ ". *?\")", Regexoptions.multiline |regexoptions.ignorecase); - strings_www58com = m_www58com.groups["g_58com"]. Value; $ stringS_58cooper = M_58cooper. groups["G_58cooper"]. Value; the stringS_ppu = M_ppu. groups["Ppu"]. Value; the stringCook ="Cookies:"+ S_58cooper +";"+ S_ppu +";"+s_www58com; the theRequest = (HttpWebRequest) webrequest.create ("http://my.58.com/?pts="+num); -Request. Referer ="Http://passport.58.com/dounionlogin"; inRequest. Method ="GET"; the request. Headers.add (cook); the AboutResponse =(HttpWebResponse) request. GetResponse (); the using(StreamReader sr =NewStreamReader (response. GetResponseStream ())) the { theHTML =Sr. ReadToEnd (); + } -Tbx. Text =html; the }Bayi}
Test Automatic Login 58