C#怎么用post传值。然后在webrowers里显示提交后的网页啊求大神帮助
2个回答
展开全部
这段代码你试试: Encoding encoding = Encoding.GetEncoding( "GB2312 "); string strUrl = @ "http:// " + DefaultIP + " " + DefaultUrl + " "; string postData = "username= "+UserName+ "&password= "+password+ "&area_c=&telfile1= "+TelePhones+ " "; byte[] data = encoding.GetBytes(postData); // 准备HTTP请求... System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl); myRequest.Method = "POST "; myRequest.ContentType = "application/x-www-form-urlencoded "; myRequest.ContentLength = data.Length; System.IO.Stream newStream = myRequest.GetRequestStream(); // 发送数据 newStream.Write(data, 0, data.Length); newStream.Close(); //HTTP响应 System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse(); System.IO.Stream receiveStream = myResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding( "GB2312 "); System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, encode); Char[] read = new Char[256]; int count = readStream.Read(read, 0, 256); StringBuilder sb = new StringBuilder( " "); while (count > 0) { String readstr = new String(read, 0, count); sb.Append(readstr); count = readStream.Read(read, 0, 256); } myResponse.Close(); readStream.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询