我有一个cs的程序现在想登陆到一个bs系统中,请大家帮忙了,贴出一段示例代码或者提供能解决问题的链接都可以。

解决方案 »

  1.   


           private void btnLogin_Click(object sender, EventArgs e)
            {
                HttpWebRequest request =
                (HttpWebRequest)WebRequest.Create("http://s1.warlord.cn/game/login.jsp");            request.CookieContainer = cookie;
                request.Method = "POST";
                string strData = "username=" + txtName.Text + "&password=" + txtPwd.Text + "&randcode=" + txtVert.Text;            // Set the 'Method' property of the 'Webrequest' to 'POST'.
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] byte1 = encoding.GetBytes(strData);            // Set the content type of the data being posted.
                request.ContentType = "application/x-www-form-urlencoded";            // Set the content length of the string being posted.
                request.ContentLength = byte1.Length;            Stream newStream = request.GetRequestStream();            newStream.Write(byte1, 0, byte1.Length);            // Close the Stream object.
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = new StreamReader(receiveStream, Encoding.Default);            this.textBox4.Text = readStream.ReadToEnd();
                response.Close();
                readStream.Close();
                if (textBox4.Text.IndexOf("当前城堡") >= 0)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    return;
                }
                MessageBox.Show("用户名、密码或验证码错误,请重新输入");
                this.ShowVertImg();
            }
      

  2.   

            private CookieContainer cookie = new CookieContainer();
      

  3.   

    用Form内嵌axWebBrowser也可以。先用fiddler2抓取登录网站时的post数据。
    AxWebBrowser wb = new AxSHDocVw.AxWebBrowser();
    object oNull = "", oPost = "", oHeader = "Content-Type:application/x-www-form-urlencoded";
    string strPostData = "抓取的post data";
    oPost = Encoding.GetEncoding("网站使用的char-set").GetBytes(strPostData);
    wb.Navigate(strUrl, ref oNull, ref oNull, ref oPost, ref oHeader);
      

  4.   

    我这个是想在cs程序中显示一张照片,现在问题是这照片怎么再写回来啊?就是我怎么把文件夹中的照片放在流里response回来,cs这边怎么接收并显示阿。
     拜托大家了,1楼的方法登陆没有问题,现在再帮帮忙吧
      

  5.   

    假设我在虚拟目录pic中有一张照片pic1吧,我用1楼方法登陆了,怎么把他弄回来显示在cs程序中,
    现在肯定是在cs里面了,大家不要说浏览器了。
      

  6.   


       String url= "http://www.baidu.com/img/logo.gif";
       HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
       HttpWebResponse response = request.GetResponse() as HttpWebResponse;
       String filename = @"c:\logo.gif";
       FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write); // 本地保存   byte[] buff = new byte[1024 * 10]; // 10KB
       int length = 0;
       Stream img = response.GetResponseStream();   while ((length = img.Read(buff, 0, buff.Length)) > 0)
       {
          fs.Write(buff, 0, length);
          offset += length;
       }
       fs.Close();
      

  7.   

    在返回的html源码里找到图片链接,指定程序图片指向该链接行不?
      

  8.   

    你应该用WebService...除非你不能控制那个B/S系统才考虑用HTTP GET/POST模式...
      

  9.   


    登陆之后在服务器中返回要获取的内容
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pic1.jpg"));     
    Response.ContentType = "image/jpeg";
    Response.WriteFile(("pic")+"\\"+"pic1.jpg");然后在cs程序中.
    Stream img = response.GetResponseStream();