本帖最后由 chenzhangyi55 于 2011-04-15 00:50:15 编辑

解决方案 »

  1.   

    1、用抓包工具(我用的是HttpAnalyzer)查看那个网页上点击按钮的事件是GET还是POST方式发送数据的
    2、在winform上button的功能发出的数据要与网页上一致。参考代码,对号入座
    发送HTTP的GET请求:C# code
    string strURL = "http://localhost/Play/CH1/Service1.asmx/doSearch?keyword=";
    strURL +=this.textBox1.Text;
    System.Net.HttpWebRequest request;
    // 创建一个HTTP请求
    request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
    //request.Method="get";
    System.Net.HttpWebResponse response;
    response = (System.Net.HttpWebResponse)request.GetResponse();
    System.IO.Stream s;
    s = response.GetResponseStream();
    XmlTextReader Reader = new XmlTextReader(s);
    Reader.MoveToContent();
    string strValue = Reader.ReadInnerXml();
    strValue = strValue.Replace("&lt;","<");
    strValue = strValue.Replace("&gt;",">");
    MessageBox.Show(strValue); 
    Reader.Close();发送HTTP的POST请求
    C# code
    string strURL = "http://localhost/Play/CH1/Service1.asmx/doSearch";
    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("keyword");
    paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(this.textBox1.Text);
    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();
    XmlTextReader Reader = new XmlTextReader(s);
    Reader.MoveToContent();
    string strValue = Reader.ReadInnerXml();
    strValue = strValue.Replace("&lt;","<");
    strValue = strValue.Replace("&gt;",">");
    MessageBox.Show(strValue); 
    Reader.Close(); 
      

  2.   

    用webbrowser控件,可以在Winfrom中加载一个网页,下面就自己搞
      

  3.   

    我看了一些资料,很多都说用webbrowser控件,但是我还没对这方面有太大的了解,请问那个朋友可以帮我把我提问那个例子的代码和编译好的软件发给我啊?软件不用复杂,一个按钮就行了,一点那个按钮就执行的功能。这样我可以更加直观和更加有目的性的去学习了,先谢了!!
      

  4.   

    我刚刚终于试了一下用webbrowser控件,发现要等网页全部打开完成后才可以执行点击事件,这样太慢了,有没有更好的办法啊???最好给出代码!!
      

  5.   

    4楼不是已经给答案了。如果不想打开一个网页,只有模拟http请求。不过我觉得还是用webbrowser比较可靠,实现起来也容易