首页 新闻 会员 周边 捐助

HttpWebRequest 问题

-2
悬赏园豆:5 [已解决问题] 解决于 2010-09-26 15:26

我使用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
自由呼吸的主页 自由呼吸 | 初学一级 | 园豆:8
提问于:2010-09-19 15:42
< >
分享
最佳答案
0

代码?

收获园豆:5
Astar | 高人七级 |园豆:40805 | 2010-09-19 16:21
StreamReader reader = new StreamReader(s, Encoding.GetEncoding("utf-8"));//输出返回值数据 temp = reader.ReadToEnd(); result += temp; MessageBox.Show(result); }catch(Exception ex) { MessageBox.Show(ex.ToString()); }
自由呼吸 | 园豆:8 (初学一级) | 2010-09-19 17:17
其他回答(1)
0

代码发出来吧。。。

顾晓北 | 园豆:10898 (专家六级) | 2010-09-19 16:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册