首页 > 代码库 > 模拟Post
模拟Post
string d = "http://search.anccnet.com/searchResult2.aspx"; //name="__VIEWSTATE" value="http://www.mamicode.com/wEPDwULLTEzODQxNzY5NjNkZEc4gDy0wp5ERjILg2b7lTTH3F+w" //name="__EVENTVALIDATION" value="http://www.mamicode.com/wEWAwKK7u6vCQLd5eLQCQLmjL2EBxmZU7jWYoh9371phOcBPCjfgdVD" //name="keyword" //name="gdsBtn" Encoding myEncoding = Encoding.GetEncoding("gb2312"); string param = "__VIEWSTATE=" + HttpUtility.UrlEncode("/wEPDwULLTEzODQxNzY5NjNkZEc4gDy0wp5ERjILg2b7lTTH3F+w", myEncoding) + "&" + "__EVENTVALIDATION=" + HttpUtility.UrlEncode("/wEWAwKK7u6vCQLd5eLQCQLmjL2EBxmZU7jWYoh9371phOcBPCjfgdVD", myEncoding) + "&" + "keyword=" + HttpUtility.UrlEncode("6935706000259", myEncoding) + "&" + "gdsBtn=" + HttpUtility.UrlEncode("111", myEncoding); byte[] postBytes = Encoding.ASCII.GetBytes(param); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(d); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded;charset=gb2312"; req.ContentLength = postBytes.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(postBytes, 0, postBytes.Length); } string html = ""; using (WebResponse wr = req.GetResponse()) { Stream stream = wr.GetResponseStream(); StreamReader sr = new StreamReader(stream,System.Text.Encoding.GetEncoding("gb2312")); html = sr.ReadToEnd(); //在这里对接收到的页面内容进行处理 } Response.Write(html);
模拟Post
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。