这是登录页面:http://ts14.travian.com.sa/nachrichten.php
我希望程序发布用户名并通过文本框和简单糟糕的浏览器传递单词:
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)
{
}
}
}
如何让浏览器登录游戏?
答案 0 :(得分:0)
您需要向http://ts14.travian.com.sa/dorf1.php发送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;
成功登录后(解析变量sResponse),您只需重定向到该页面即可。
但要记住....您的会话将仅在运行应用程序的计算机内存在。
答案 1 :(得分:0)
{
HtmlElement ele = webBrowser1.Document.GetElementById("usernameID"); if (ele != null)
ele.InnerText = "username";
ele = webBrowser1.Document.GetElementById("passwordID"); if (ele != null)
ele.InnerText = "password";
ele = webBrowser1.Document.GetElementById("goButtonID"); if (ele != null)
ele.InvokeMember("click");
} 它运作正常
答案 2 :(得分:0)
您需要向http://www.weedi.net/vb/f-127/29251/发送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;
.