实现网络流,2年以前在学校写的程序中的一段 需要的话可以给所有源码
获取:
HttpWebRequest req=(HttpWebRequest)WebRequest.Create("
http://wall.usts.edu.cn/jf4.0/login.php?height=600");
req.KeepAlive =false;
req.ContentType = "application/x-www-form-urlencoded";
req.PreAuthenticate=true;
req.Timeout=5000;
HttpWebResponse rep=(HttpWebResponse)req.GetResponse();
Stream ReceiveStream=rep.GetResponseStream();
Encoding encode=System.Text.Encoding.GetEncoding("GB18030");
StreamReader rd=new StreamReader (ReceiveStream,encode);
发送和回应:
HttpWebRequest req=(HttpWebRequest)WebRequest.Create("
http://210.29.0.1/jf4.0/main.php");
req.KeepAlive = false;
req.Method ="POST";
req.ContentType = "application/x-www-form-urlencoded";
req.PreAuthenticate=true;
req.Timeout=5000;
string Name=this.textBox1.Text ;
string Password=this.textBox2.Text.Length <32?calcMD5(calcMD5(this.textBox2.Text+logpwd)):this.textBox2.Text;
string Method=this.radioButton3.Checked ?"login":(this.radioButton4.Checked?"stop":"query");
string TimeLimit=this.comboBox1.Text ;
string user_select_acco_mode="ON";
string user_select_use_mode=(this.radioButton1.Checked ?"ON":"OFF");
string log=logText ;
StringBuilder MyStringBuilder =
new StringBuilder("Name="+Name+'&'
+"Password="+Password+'&'
+"Method="+Method+'&'
+"TimeLimit="+TimeLimit+'&'
+"user_select_acco_mode="+user_select_acco_mode+'&'
+"user_select_use_mode="+user_select_use_mode+'&'
+"log="+log
);
byte[] byte1=Encoding.UTF8.GetBytes (MyStringBuilder.ToString());
req.ContentLength=byte1.Length ;
Stream newStream=req.GetRequestStream ();
newStream.Write(byte1,0,byte1.Length );
newStream.Close();
HttpWebResponse rep=(HttpWebResponse)req.GetResponse();
Stream ReceiveStream=rep.GetResponseStream();
Encoding encode=System.Text.Encoding.GetEncoding("GB18030");
StreamReader rd=new StreamReader (ReceiveStream,encode);
string str=rd.ReadToEnd ();
我曾花了好多时间弄懂了这点,原来网页的编码是GB18030,原来还以为是ANSCII, UNICODE,GB2312 ....现在想起来当时真好玩
[此贴子已经被作者于2006-2-5 15:08:04编辑过]