本来某网站是 以参数传递日期的, 然后可以查到某日期的一个页面,我再正则取自己要的东西。如今人家改版了,把日期栏变成了表单传输的, 我该怎么只用超链接过去,顺便能传递这个 日期参数??

解决方案 »

  1.   

    跳转到一个post提交的页面  然后给他post上去。。 
      

  2.   


    HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create("http://www.safe.gov.cn/AppStructured/view/project_syRMBQuery.action");
        try
            {
                using (StreamReader sr = new StreamReader(wr.GetResponse().GetResponseStream(), Encoding.GetEncoding(936)))
                {
                    htmlBody = sr.ReadToEnd();
                }
            }
            catch
            {
            }  我的代码, 请指教该如何做,那个link是有效的
      

  3.   

    参考如下发送带post请求
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.KeepAlive = false;
                req.Method = "POST";
                req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
                req.Credentials = CredentialCache.DefaultCredentials;
                Encoding encode = new UTF8Encoding();
                using (Stream stream = req.GetRequestStream())
                {
                    Dictionary<string, string> nvc = new Dictionary<string, string>();
                    nvc.Add("Content", HttpUtility.UrlEncode(content, encode));
                    nvc.Add("Type", "1");
                    nvc.Add("StartDate", DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd 00:00:00"));
                    nvc.Add("EndDate", DateTime.Now.Date.ToString("yyyy-MM-dd 00:00:00"));
                    string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
                    byte[] boundarybytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
                    req.ContentType = "multipart/form-data; boundary=" + boundary;
                    string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
                    foreach (string key in nvc.Keys)
                    {
                        stream.Write(boundarybytes, 0, boundarybytes.Length);
                        string formitem = string.Format(formdataTemplate, key, nvc[key]);
                        byte[] formitembytes = encode.GetBytes(formitem);
                        stream.Write(formitembytes, 0, formitembytes.Length);
                    }
                    stream.Write(boundarybytes, 0, boundarybytes.Length);
                    byte[] trailer = Encoding.ASCII.GetBytes("\r\nContent-Type: application/x-form-www-urlencoded\r\n\r\n\r\n--" + boundary + "--\r\n");
                    stream.Write(trailer, 0, trailer.Length);
                }            WebResponse res = req.GetResponse();
                StreamReader sr = new StreamReader(res.GetResponseStream(), encode);
                string result = sr.ReadToEnd();