First open the Web site, view the source file, and find his login form section.
yo5e. Tw4c8rxw}0itpub Personal Space Xiby9n/v1nz
For example: itpub personal space hb6u; L_
<form. Name= "Login" action= "loginmain.jsp" method= "POST" target= "_top" >itpub personal space 9{t#vd/s ' 9Iy
<table width= "218" border= "0" cellspacing= "0" cellpadding= "0" >itpub personal space!? (pn%z4mm#srf4h
<tr>itpub personal space. Ma,ci (Rwn0y:t G}
<TD width= "height=" class= "hui" ><div align= "right" > Username:</div></td>
W) yj*n; Z~kw0 <td width= "height=" ><input class= "hui" id= "username" itpub Personal space $x/iy9k "W g-j7f ' E
Maxlength= "size=" name= "username" id= "username"/></td>
cp5w|:| V5o0 </tr>itpub Personal Space 7cwN zzc/6f2@
<tr>
$b%p!oc/r!f:f0 <td height= "class= hui" ><div align= "right" > Password: </div></td>itpub personal space 3yQ /uff5~{]
<TD height= ><input class= "hui" id= "passwd" itpub personal space-g1ey/fc[
Maxlength= "size=" name= "passwd" type= "password" id= "passwd"/></td>itpub personal space wh (@7rgi* '
</tr>itpub Personal space $[B (q8uq,s ' s.x) P
</table>itpub personal space ' n9e ' sd#i^? SR
</form>itpub Personal Space {#Z {H4I:QB
As can be seen from the above form, the form submission method is: POST, submitted to loginmain.jsp processing, a total of two form items namely: username, passwditpub personal space 0s{f$y+q9q]. I4@r%v
Itpub personal Space 8e{n7b8 ' 6M*OW6NB
The following is a C # impersonation login program: Login.cs
F (H&hj c2d) A0
^ "u+m! I|g7~0 using System;
9XG (i^u$b!o.z@0 using system.data;itpub personal space 8L q%xc0f m*m
Using system.net;itpub personal space iuqw T ' OV
Using system.text;itpub personal space p+rd ' *mw0s
Using system.io;itpub personal Space u2c2g~ (o ({#O
Using system.text.regularexpressions;itpub personal space q,v |7q5z "T
*j9n (~+fq3q*n8s.v0///<summary>
@0nx1~3ty (q0///login to the site and get cookiesitpub personal space e nc*c~#? F,]&b P
</summary> itpub Personal Space C}j.l;c1tm '}j
<returns> cookie information for successful login </returns>
6fM ' z7l2q-g8d0x0 public static Cookiecontainer Get_login () itpub personal space c| K) ~ '
{
n8eoyz6z3f}0 cookiecontainer cc = new Cookiecontainer ();
1/j6x+x+xw*[0 string formurl = "http://blog.hnce.net/loginMain.jsp"; Handles the absolute URL address of the form itpub personal space @gf "V0kz,iiv
String FormData = "username=slick&passwd=hedy12345"; The form needs to submit the parameters and note that the information you have registered is changed.
P|7m_2b9[0 asciiencoding encoding = new ASCIIEncoding ();
a9bj7m:s|+ ' 4~a0 byte []Data= Encoding. GetBytes (FormData); Itpub personal space ' le0o@_
, SuL]h:e! ' d%t0 HttpWebRequest request = (HttpWebRequest) webrequest.create (Formurl);
Q z-x9n2yx2w; BY0 request. method = "POST"; How data is submitted
*Y6PN lw#vi$?1?0 request. ContentType = "application/x-www-form-urlencoded"; itpub personal space 4f*l$di g
Request. ContentLength = data. Length;
' U ob&g4@nt0 request. useragent = "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.1; SV1. NET CLR 1.1.4322) ";
+m,e7f pC0//Simulate a useragent itpub personal space X) | zu/s
Stream newstream = Request. GetRequestStream ();
B.^x ' [S0 newstream.write (data, 0, data. Length); Itpub Personal Space 4n*v4y+b! G [&w/l
Itpub Personal Space s-z{{g8f}t Z
Newstream.close ();
(u2hxm3wpt0
) ZY [7[m.d0 request. Cookiecontainer = CC;
]f {oi4e s_gj0 itpub personal space h d/fkm8r (| g
HttpWebResponse response = (HttpWebResponse) request. GetResponse () itpub personal space ggx#t| Z5x7d;je
Cc. ADD (response. Cookies); itpub Personal Space 3ZI u!gp|
Stream stream = Response. GetResponseStream ();
F an6_q@p/~+u0 String webcontent = new StreamReader (stream, System.Text.Encoding.Default). ReadToEnd ();
$@.ci;? F@F2DC0 return cc;
}e7i;oa6t; Y4~0}
x:/5a1[) w$l!e[d0itpub personal space ('? #O! L*uu&e
Call the above method to get what you need to log in to see. Cookiecontainer cc = new Cookiecontainer ();
qj9ry6ig/e e4f0 cc = Login.get_login (); Get Login Cookies
2JzRj ' z/{sJ0 itpub personal space [1pb:e B!L#I-L;HBCL
String photoclassurl = "http://blog.hnce.net/xxx.jsp";
GD m[[g0 HttpWebRequest myrequest = (HttpWebRequest) webrequest.create (Photoclassurl);
9| " M c/a^ G "B0 myrequest.cookiecontainer = cc;itpub Personal Space%s|5i^&tj5{v"/
HttpWebResponse myresponse = (HttpWebResponse) myrequest.getresponse () itpub personal space 3l+pe khr+l
Cc. ADD (myresponse.cookies); Itpub personal space t7@/y!r? E
Stream MyStream = Myresponse.getresponsestream ();
Z2RJ (F f;v0 string sHtml = new StreamReader (MyStream, System.Text.Encoding.Default). ReadToEnd ();
Itpub personal Space 1m5x$ ' 5^:? g0j
Itpub personal Space 3P ' 7_/m ' 8g$p (?) Qt
sHTML is what you see after you log in.