[C#]代码
01 |
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create( "" );
|
02 |
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)" ;
|
04 |
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" ;
|
05 |
req.Headers.Add( "Accept-Language: en-us,en;q=0.5" );
|
06 |
req.Headers.Add( "Accept-Encoding: gzip,deflate" );
|
07 |
req.Headers.Add( "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" );
|
09 |
req.Headers.Add( "Keep-Alive: 300" );
|
10 |
req.Referer = "copy from url" ;
|
12 |
req.ContentType = "application/x-www-form-urlencoded" ;
|
14 |
String Username = copy from url; |
15 |
String PassWord = copy from url; |
17 |
StreamWriter sw = new StreamWriter(req.GetRequestStream());
|
18 |
sw.Write( string .Format( "&loginname={0}&password={1}&btnSubmit=Log In&institutioncode=H4V9KLUT45AV&version=2" , Username, PassWord));
|
20 |
HttpWebResponse response = (HttpWebResponse)req.GetResponse(); |
22 |
StreamReader reader = new StreamReader(response.GetResponseStream());
|
23 |
string tmp = reader.ReadToEnd();
|
[代码] Cookie 处理
01 |
CookieCollection cookiesResponse = new CookieCollection();
|
05 |
foreach ( string cookie in response.Headers[ "Set-Cookie" ].Split( ';' ))
|
07 |
string name = cookie.Split( '=' )[0];
|
08 |
string value = cookie.Substring(name.Length + 1);
|
09 |
cookiesResponse.Add( new Cookie(name.Trim(), value.Trim(), path, domain));
|
|
请发表评论