我使用HttpWebRequest 使用发送post请求
读取流的时候提示流不可读错误,是什么问题导致的
问题补充:
try
{
String endUrl = "http://home.cnblogs.com/110688/feed/question/login.aspx?ReturnUrl=http%3a%2f%2fhome.cnblogs.com%2f110688%2ffeed%2fquestion%2f ";
String postData = "tbUserName=abc&tbPassword=sss&chkRemember";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(endUrl);
httpWebRequest.Method = "POST";//使用发送的方法
//httpWebRequest.ContentType = "application/x-www-form-urlencoded";//设置post包包头
httpWebRequest.CookieContainer = new CookieContainer();//创建一个Cookle
httpWebRequest.Accept = " image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*";//是指表头值
httpWebRequest.KeepAlive = true;//保持持久性连接
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; QQDownload 661; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)";
httpWebRequest.ContentType = "text/html; charset=gb2312";
byte[] buffer = Encoding.ASCII.GetBytes(postData);//创建字节流
httpWebRequest.ContentLength = buffer.Length;//设置包体长度
httpWebRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
httpWebRequest.GetRequestStream().Close();
string result = "";//获取返回值
string temp = "";//临时变量
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream s = httpWebRequest.GetRequestStream();//获取返回值数据流
long length = httpWebResponse.ContentLength;//获取字节数组长度
StreamReader