i have the following problem and it would be great if s.o. could help me.
I try to write a simple bot for a browsergame which uses the HttpWebRequest and Response classes from C#. Currently i try to log in with the following script but i only get back to the login page. When i try to catch a site for logged in members only i also only get the login page. There has to be a problem with the cookie but i don't know where
Code:
class HttpHelper
{
private CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request;
HttpWebResponse response;
StreamReader sr;
public string GetHtml(string Url)
{
request = (HttpWebRequest)HttpWebRequest.Create(Url);
request.Referer = "http://s40.wurzelimperium.de";
request.AllowAutoRedirect = true;
request.ServicePoint.Expect100Continue = false;
request.Timeout = 10000;
request.CookieContainer = cookieContainer;
request.Method = "GET";
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
response = (HttpWebResponse)request.GetResponse();
Console.WriteLine();
sr = new StreamReader(response.GetResponseStream());
string html = sr.ReadToEnd();
sr.Close();
response.Close();
return html;
}
public void Login()
{
HttpWebResponse res;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.wurzelimperium.de/serverwahl_login.php");
req.AllowAutoRedirect = true;
req.Method = "POST";
req.ServicePoint.Expect100Continue = false;
req.Timeout = 10000;
req.CookieContainer = cookieContainer;
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3";
req.ContentType = "application/x-www-form-urlencoded";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginDataBytes = encoding.GetBytes("server=server40&submitlogin=Einloggen&login=tobu&dummy=12346&pass=MTIzNDY%3D");
req.ContentLength = loginDataBytes.Length;
Stream stream = req.GetRequestStream();
stream.Write(loginDataBytes, 0, loginDataBytes.Length);
stream.Close();
res = (HttpWebResponse)req.GetResponse();
res.Close();
}
}
I created a WPF-Project so that i can see the results.
Here my call:
Code:
Login()
webBrowser1.DocumentText = GetHtml("http://s40.wurzelimperium.de/garten_map.php")
€dit:
I've tested it with other games. Works fine there. I've really no clue why it doesn't work there
Thorbardin






