winfrom C Post提交 带参数 ,返回值
作者:互联网
分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net
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();
}
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net
标签:string,winfrom,request,System,strValue,Reader,返回值,Post,payload 来源: https://www.cnblogs.com/sjwudhwhhw/p/10509146.html