C# 发布用户名并在网站(travian)中自动传递并登录

C# 发布用户名并在网站(travian)中自动传递并登录,c#,login,C#,Login,这是登录页面: 我希望程序将用户名和密码发布到文本框和我的简单浏览器中: 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; namespace WindowsFormsApplic

这是登录页面:

我希望程序将用户名和密码发布到文本框和我的简单浏览器中:

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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(textBox1.Text);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://ts14.travian.com.sa");
            textBox1.Text = "متصفح خاص بترافيان";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(label1.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            webBrowser1.Refresh();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://ts14.travian.com.sa/logout.php");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(textBox2.Text);

        }

        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }
    }
}

要让浏览器登录到游戏,我必须做什么?

您需要执行POST HTTP请求来传递所需的表单变量。您需要了解他们是如何处理登录请求的。您可以尝试以下方法:

            StreamWriter Sw = null;
            StreamReader Sr = null;
            string sUsername = "aUsername";
            string sPassword = "aValidPass";

            string data = string.Format("name={0}&password={1}", sUsername, sPassword);

            HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://ts14.travian.com.sa/dorf1.php");
            Req.Method = "POST";
            Req.KeepAlive = true;

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(data);
            Req.ContentType = "application/x-www-form-urlencoded";
            Req.ContentLength = byte1.Length;
            Stream newStream = Req.GetRequestStream();
            newStream.Write(byte1, 0, byte1.Length);
            newStream.Close();

            Sr = new StreamReader(((HttpWebResponse)Req.GetResponse()).GetResponseStream());
            sResponse = Sr.ReadToEnd();
            int cookieCount = cookieJar.Count;
            Sr.Close();
            Sw = null;
 StreamWriter Sw = null;
        StreamReader Sr = null;
        string sUsername = "aUsername";
        string sPassword = "aValidPass";

        string data = string.Format("name={0}&password={1}", sUsername, sPassword);

        HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://ts14.travian.com.sa/dorf1.php");
        Req.Method = "POST";
        Req.KeepAlive = true;



                                                                    .
一旦成功登录(解析变量sResponse),就可以重定向到页面


但请记住。。。。您的会话将只在运行应用程序的计算机中运行。

thx man我找到了一种方法,通过检测HtmlelementId然后更改其值来实现 像这样

{

}
它工作正常

您需要执行POST HTTP请求来传递所需的表单变量。您需要了解他们是如何处理登录请求的。您可以尝试以下方法:

            StreamWriter Sw = null;
            StreamReader Sr = null;
            string sUsername = "aUsername";
            string sPassword = "aValidPass";

            string data = string.Format("name={0}&password={1}", sUsername, sPassword);

            HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://ts14.travian.com.sa/dorf1.php");
            Req.Method = "POST";
            Req.KeepAlive = true;

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(data);
            Req.ContentType = "application/x-www-form-urlencoded";
            Req.ContentLength = byte1.Length;
            Stream newStream = Req.GetRequestStream();
            newStream.Write(byte1, 0, byte1.Length);
            newStream.Close();

            Sr = new StreamReader(((HttpWebResponse)Req.GetResponse()).GetResponseStream());
            sResponse = Sr.ReadToEnd();
            int cookieCount = cookieJar.Count;
            Sr.Close();
            Sw = null;
 StreamWriter Sw = null;
        StreamReader Sr = null;
        string sUsername = "aUsername";
        string sPassword = "aValidPass";

        string data = string.Format("name={0}&password={1}", sUsername, sPassword);

        HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://ts14.travian.com.sa/dorf1.php");
        Req.Method = "POST";
        Req.KeepAlive = true;



                                                                    .

提供的代码有点混乱,其中有未使用的变量,实际上没有显示如何向服务器发起请求