zoukankan      html  css  js  c++  java
  • 模拟Post

       string d = "http://search.anccnet.com/searchResult2.aspx";
            //name="__VIEWSTATE"  value="/wEPDwULLTEzODQxNzY5NjNkZEc4gDy0wp5ERjILg2b7lTTH3F+w"
            //name="__EVENTVALIDATION"    value="/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);


     这个也不错 http://www.cnblogs.com/oec2003/p/3322956.html

  • 相关阅读:
    [LeetCode] 67. 二进制求和
    [LeetCode] 66. 加一
    [LeetCode] 65. 有效数字
    [LeetCode] 63. 不同路径 II
    [LeetCode] 64. 最小路径和
    [LeetCode] 61. 旋转链表
    [LeetCode] 62. 不同路径
    [LeetCode] 59. 螺旋矩阵 II
    [LeetCode] 60. 第k个排列
    [LeetCode] 58. 最后一个单词的长度
  • 原文地址:https://www.cnblogs.com/crazyair/p/4210457.html
Copyright © 2011-2022 走看看