- public void PostMoths()
- {
- string strURL = "http://www.cqjg.gov.cn/newwww/c7/clwz.asp";
- System.Net.HttpWebRequest request;
- request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
- //Post请求方式
- request.Method = "POST";
- //内容类型
- request.ContentType = "application/x-www-form-urlencoded";
- //参数经过URL编码
- string paraUrlCoded = System.Web.HttpUtility.UrlEncode("LicenseTxt");
- paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(txtCarId .Text.Trim());
- paraUrlCoded +="& "+ System.Web.HttpUtility.UrlEncode("VIN");
- paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(txtCarNumber.Text.Trim());
- byte[] payload;
- //将URL编码后的字符串转化为字节
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
- //设置请求的ContentLength
- request.ContentLength = payload.Length;
- //获得请求流
- Stream writer = request.GetRequestStream();
- //将请求参数写入流
- writer.Write(payload, 0, payload.Length);
- //关闭请求流
- writer.Close();
- System.Net.HttpWebResponse response;
- //获得响应流
- response = (System.Net.HttpWebResponse)request.GetResponse();
- System.IO.Stream s;
- s = response.GetResponseStream();
- string StrDate = "";
- string strValue = "";
- StreamReader Reader = new StreamReader(s,Encoding.Default);
- while ((StrDate= Reader.ReadLine())!=null)
- {
- strValue += StrDate+"\r\n";
- }
- // txtInfo.Text = strValue;
- txtInfo.Text= FindContent(strValue);
- //XmlTextReader Reader = new XmlTextReader(s);
- //Reader.MoveToContent();
- //string strValue = Reader.ReadInnerXml();
- //strValue = strValue.Replace("<", "<");
- //strValue = strValue.Replace(">", ">");
- //MessageBox.Show(strValue);
- //Reader.Close();
- }
winfrom post 向服务器请求数据
最新推荐文章于 2024-07-01 12:00:06 发布