string url = "http://www.861.cn/manage.php?cmd=login";
Uri u = new Uri(url);
//这是一个发送请求的类
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(url);
//请求头中的类型为POST
hwr.Method = "POST";
//WebHeaderCollection whc = hwr.Headers;
//下面这些你自己看一下http报头中就知道是指什么
hwr.Accept= "image/gif, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*";
hwr.Referer = "http://www.861.cn/manage.php";
hwr.KeepAlive = true;
//hwr.AcceptLanguage = "zh-cn";
hwr.ContentType="application/x-www-form-urlencoded";
hwr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)";
hwr.ContentLength=77;
//这些呢是表示异步请求开始,ReadCallback是表示下面的ReadCallback方法
//IAsyncResult result=(IAsyncResult) hwr.BeginGetRequestStream(new AsyncCallback(ReadCallback),hwr);
//这个是取得服务器回应的类
ASCIIEncoding encoding = new ASCIIEncoding();
string data = "DName=ynusi&DSuff=.com&DPass=123456789&B1=%A2%A1%B5%C7%A1%A1%C2%BC%A1%A1";
byte[] b = encoding.GetBytes(data);
Stream newStream = hwr.GetRequestStream();
// Send the data.
newStream.Write(b, 0, b.Length);
newStream.Flush();
newStream.Close();
HttpWebResponse hwrp=(HttpWebResponse)hwr.GetResponse();
//这个是把服务器回应的状态代码的描述取到label1中显示
label1.Text=hwrp.StatusCode.ToString();
//下面呢是取得服务器中返回的信息,总得来说就是服务器返回给我的页的html页的代码
Stream s = hwrp.GetResponseStream();
StreamReader sr = new StreamReader(s,Encoding.GetEncoding("gb2312"));
textBox1.Text = sr.ReadToEnd();
sr.Close();为什么我的这段代码发送不出我的请求正文呢?只能把请求行,和请求报头发出去,可是就是发不出我的请求正文,真是晕死,哪位高手帮忙看看.
Uri u = new Uri(url);
//这是一个发送请求的类
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(url);
//请求头中的类型为POST
hwr.Method = "POST";
//WebHeaderCollection whc = hwr.Headers;
//下面这些你自己看一下http报头中就知道是指什么
hwr.Accept= "image/gif, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*";
hwr.Referer = "http://www.861.cn/manage.php";
hwr.KeepAlive = true;
//hwr.AcceptLanguage = "zh-cn";
hwr.ContentType="application/x-www-form-urlencoded";
hwr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)";
hwr.ContentLength=77;
//这些呢是表示异步请求开始,ReadCallback是表示下面的ReadCallback方法
//IAsyncResult result=(IAsyncResult) hwr.BeginGetRequestStream(new AsyncCallback(ReadCallback),hwr);
//这个是取得服务器回应的类
ASCIIEncoding encoding = new ASCIIEncoding();
string data = "DName=ynusi&DSuff=.com&DPass=123456789&B1=%A2%A1%B5%C7%A1%A1%C2%BC%A1%A1";
byte[] b = encoding.GetBytes(data);
Stream newStream = hwr.GetRequestStream();
// Send the data.
newStream.Write(b, 0, b.Length);
newStream.Flush();
newStream.Close();
HttpWebResponse hwrp=(HttpWebResponse)hwr.GetResponse();
//这个是把服务器回应的状态代码的描述取到label1中显示
label1.Text=hwrp.StatusCode.ToString();
//下面呢是取得服务器中返回的信息,总得来说就是服务器返回给我的页的html页的代码
Stream s = hwrp.GetResponseStream();
StreamReader sr = new StreamReader(s,Encoding.GetEncoding("gb2312"));
textBox1.Text = sr.ReadToEnd();
sr.Close();为什么我的这段代码发送不出我的请求正文呢?只能把请求行,和请求报头发出去,可是就是发不出我的请求正文,真是晕死,哪位高手帮忙看看.
//这些呢是表示异步请求开始,ReadCallback是表示下面的ReadCallback方法
//IAsyncResult result=(IAsyncResult) hwr.BeginGetRequestStream(new AsyncCallback(ReadCallback),hwr);
hwr.ContentLength=77呢是表示我的请求内容的长度,这是HTTP请求数据中的最基本的呀,怎么你也不知道?
这样试试,为什么要设成77呢?