Answer the question
In order to leave comments, you need to log in
Authorization on en.grepolis.com C# + .NET
I'm trying to write an authorization code on ru.grepolis.com
But I'm stuck on the second step.
First I send a Get request, I get cookies:
request = (HttpWebRequest)HttpWebRequest.Create("http://ru.grepolis.com");
//request.Proxy = new WebProxy("127.0.0.1", 8888);
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3");
request.KeepAlive = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string sCookies = "";
if (!String.IsNullOrEmpty(response.Headers["Set-Cookie"]))
{
sCookies = response.Headers["Set-Cookie"];
}
request = (HttpWebRequest)HttpWebRequest.Create("http://ru.grepolis.com/start/index?action=login_from_start_page");
request.Method = "POST";
request.Referer = "http://ru.grepolis.com";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3");
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
// передаем куки, полученные в предыдущем запросе
if (!String.IsNullOrEmpty(sCookies))
{
request.Headers.Add(HttpRequestHeader.Cookie, sCookies);
}
request.AllowAutoRedirect = true;
// Формируем строку с параметрами
string secondStepForm = "json={\"name\":\"*********\",\"password\":\"***********\",\"passwordhash\":\"\",\"autologin\":false,\"window_size\":\"1263x535\"}";
// передаем параметры
byte[] EncodedPostParams = Encoding.ASCII.GetBytes(secondStepForm);
request.ContentLength = EncodedPostParams.Length;
// Записываем данные в поток
request.GetRequestStream().Write(EncodedPostParams, 0, EncodedPostParams.Length);
request.GetRequestStream().Close();
// делаем запрос
response = (HttpWebResponse)request.GetResponse();
Answer the question
In order to leave comments, you need to log in
Look with the help of some sniffer (for example WireShark ) - what exactly goes to the server and from the server in the case of a browser <-> site and see what goes through your application <-> site.
I sort of figured out one problem, it wasn’t enough
request.ServicePoint.Expect100Continue = false;
int unixTime = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
Yes, well, in what basics will they tell me what kind of insertion is at the end of Unix Timestamp?
Has anyone experienced this in practice? Or, by virtue of experience, he may know what it is ...
How to get a 13-digit value of milliseconds seems to have figured out:
long unixTime = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question