这是一个查汉字的页面
网址:http://open-lit.com/postgb.php?menu=&gbid=217&cid=1&bid=10737&search=&start=自已用C# 写了段代码Post 来提交查询,但是没有成功,代码如下:        ASCIIEncoding encoding = new ASCIIEncoding();
        string postData = "gbid=" + "217";
        postData += ("&cid=" + "1");
        postData += ("&bid=" + "10737");
        //postData += ("&Accept=" + strsubmit);
        byte[] data = encoding.GetBytes(postData);
        // Prepare web request...
        System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://open-lit.com/postgb.php");
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.ContentLength = data.Length;
        Stream newStream = myRequest.GetRequestStream();
        // Send the data.
        newStream.Write(data, 0, data.Length);
        newStream.Close();
        HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
        StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
        string content = reader.ReadToEnd();
        textBox1.Text = content; 
请问错在哪里?

解决方案 »

  1.   

    有可能对方有防站外提交,如果有防站外提交就要用更高深的技术,IP欺骗,cookies欺骗之类的
      

  2.   

    使用httpwebrequest实现post提交
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");  
    string postData = "";  
    byte[] data = Encoding.UTF8.GetBytes(postData);  
    request.Method = "POST"; 
      

  3.   

    //通过Post发送的数据
       string payload="chkbook=book&keyword=管理";
       WebRequest req = WebRequest.Create("http://localhost/pceo/Search.aspx");
       req.Method = "POST";
       req.ContentType = "application/x-www-form-urlencoded";
       StringBuilder UrlEncoded = new StringBuilder();
       Char[] reserved = {?, =, &};
       byte[] SomeBytes = null;
       if (payload != null) 
       {
        int i=0, j;
        while(i<payload.Length)
        {
         j=payload.IndexOfAny(reserved, i);
         if (j==-1)
         {
          UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, payload.Length-i),System.Text .Encoding .GetEncoding ("gb2312")));
          break;
         }
         UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, j-i),System.Text .Encoding .GetEncoding ("gb2312")));
         UrlEncoded.Append(payload.Substring(j,1));
         i = j+1;
        }
        SomeBytes = Encoding.Default.GetBytes(UrlEncoded.ToString());
        req.ContentLength = SomeBytes.Length;
        Stream newStream = req.GetRequestStream();
        newStream.Write(SomeBytes, 0, SomeBytes.Length);
        newStream.Close();
       } 
       else 
       {
        req.ContentLength = 0;
       }
       try 
       {
        WebResponse result = req.GetResponse();
        Stream ReceiveStream = result.GetResponseStream();    Byte[] read = new Byte[512];
        int bytes = ReceiveStream.Read(read, 0, 512);    txtHTML.InnerHtml = "";
        while (bytes > 0)
        {     // 注意:
         // 下面假定响应使用 UTF-8 作为编码方式。
         // 如果内容以 ANSI 代码页形式(例如,932)发送,则使用类似下面的语句:
         //  Encoding encode = System.Text.Encoding.GetEncoding("shift-jis");
         Encoding encode = System.Text.Encoding.GetEncoding("gb2312");
         txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read, 0, bytes);
         bytes = ReceiveStream.Read(read, 0, 512);
        }
       } 
       catch(Exception) 
       {
        txtHTML.InnerHtml = "检索页时出错";
       }
      

  4.   

    没有保存cookie。用CookieContainer 
      

  5.   

    试着截个断点,然后看对方服务器给你返回了什么数据,中间有没有发生什么异常以及异常的具体内容再作判断 并进一步修改程序(如果可能)1 如果对方很明确地拒绝了你的请求,那你试着模拟正常的请求伪造一些 UserAgent 和 Cookie 数据放在请求头里(比如确实是正确的URL、Post 格式也对了,却给你返回 400 和 404 等错误)
    2 检查你的请求格式、URL和网络访问是否出现了异常,而导致根本请求就没有到达对方的服务器_____________________________________唉,能不能好好回答别人的问题,看清楚问题再回复。
    总是回复一些没有意义的东西,能帮别人解决问题吗?没看楼主的代码已经写得挺好了,POST也实现了,人不用你们这些大哥来教他怎么 POST说得激进点,希望楼上 2、3、5 楼诸位不要生气,更不要怀恨;我知道你们很热心,并期待通过这热心来得到得分以作为回报,但至少要能帮人解决问题吧,要不然拿这些分不手软么
      

  6.   


    自已研究了一下,这段代码还需要再改改就差不多达到目的了:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            string url = "http://open-lit.com/postgb.php?gbid=217&cid=1";
                this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
                webBrowser1.Navigate(url);
            }        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                HtmlElement btnSubmit = webBrowser1.Document.All["btnschdic"];
                HtmlElement showdic = webBrowser1.Document.All["showdic"];            if (showdic == null || btnSubmit == null)
                    return;            showdic.SetAttribute("value", "雲");
                btnSubmit.InvokeMember("click");
                return;
            }        private void button1_Click(object sender, EventArgs e)
            {
                string url = "http://open-lit.com/postgb.php?gbid=217&cid=1";
                this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
                webBrowser1.Navigate(url);
            }
        }
    }