111,130
社区成员
发帖
与我相关
我的任务
分享
private bool PostWebRequest()
{
CookieContainer cc = new CookieContainer(); //建立保存cookies的容器
string pos tData = "user=" + strUser + "&pass=" + strPsd;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("/chk.asp"));
webRequest2.CookieContainer = cc; //设置cookies
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
StreamReader sr2=new StreamReader(response2.GetResponseStream(), Encoding.Default);
string text2 = sr2.ReadToEnd();
......
}