Hey guys im trying to automate my account creation for reasons heh.
So heres what the site actually "POST" to create the account.
and heres my code...
PHP Code:
public static string CreateAccount()
{
//get token
string html;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://secure.tibia.com/account/?subtopic=createaccount");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
html = reader.ReadToEnd();
response.Close();
HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument();
htmldoc.LoadHtml(html);
HtmlAgilityPack.HtmlDocument doc = htmldoc;
HtmlNodeCollection PHeaderNodes = GetNodes("//input", doc);
// Console.WriteLine("Node:" + 66 + " | " + PHeaderNodes[66].Attributes[2].Value);
//create account
HttpWebRequest request1 = (HttpWebRequest)HttpWebRequest.Create("https://secure.tibia.com/account/?subtopic=createaccount");
request1.Method = "POST";
request1.KeepAlive = true;
request1.ContentType = "application/x-www-form-urlencoded";
request1.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
string account = "sa4f89sa4fsa84fsa84f"; //random string
string email = account+"@"+account+".com"; //works
string postData = "&accountname=" + account +
"&email=" + email +
"&password1=" + account +
"&password2=" + account +
"&name=" + Account.Character.GetName()+ //gets a random name
"&sex=male"+
"&server_location=" + "on"+
"&server_pvp_type=" + "on"+
"&world=" + "Server_Eldera"+
"&agreeagreements=" + "true"+
"&token=" + PHeaderNodes[66].Attributes[2].Value + //gets the token from the page
"&step" + "docreate"+
"&noframe=" +
"&Submit.x" + "131" +
"&Submit.y" + "25";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request1.ContentLength = byteArray.Length;
Stream dataStream = request1.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
dataStream = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(dataStream);
string responseFromServer = reader1.ReadToEnd();
reader1.Close();
dataStream.Close();
response1.Close();
return responseFromServer;
}
}
for some reason it doesnt work and when i try to look at the response in a browser the only thing that isnt filled is the world. anyone know how to fix this? or maybe a better way to do this?
-----fixed i was missing some "="
PHP Code:
public static string CreateAccount()
{
//get token
string html;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://secure.tibia.com/account/?subtopic=createaccount");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
html = reader.ReadToEnd();
response.Close();
HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument();
htmldoc.LoadHtml(html);
HtmlAgilityPack.HtmlDocument doc = htmldoc;
HtmlNodeCollection PHeaderNodes = GetNodes("//input", doc);
// Console.WriteLine("Node:" + 66 + " | " + PHeaderNodes[66].Attributes[2].Value);
//create account
HttpWebRequest request1 = (HttpWebRequest)HttpWebRequest.Create("https://secure.tibia.com/account/?subtopic=createaccount");
request1.Method = "POST";
request1.KeepAlive = true;
request1.ContentType = "application/x-www-form-urlencoded";
request1.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
string account = "sa4f89sa4fsa84fsa84f"; //random string
string email = account+"@"+account+".com"; //works
string postData = "&accountname=" + account +
"&email=" + email +
"&password1=" + account +
"&password2=" + account +
"&name=" + Account.Character.GetName()+ //gets a random name
"&sex=male"+
"&server_location=" + "on"+
"&server_pvp_type=" + "on"+
"&world=" + "server_Eldera"+
"&agreeagreements=" + "true"+
"&token=" + PHeaderNodes[66].Attributes[2].Value + //gets the token from the page
"&step=" + "docreate"+
"&noframe=" +
"&Submit.x=" + "131" +
"&Submit.y=" + "25";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request1.ContentLength = byteArray.Length;
Stream dataStream = request1.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
dataStream = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(dataStream);
string responseFromServer = reader1.ReadToEnd();
reader1.Close();
dataStream.Close();
response1.Close();
return responseFromServer;
}
}
enjoy