S
S
Seganapa2012-12-14 13:48:49
.NET
Seganapa, 2012-12-14 13:48:49

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"];
                }


Then, using the received cookies, I send a Post request:

                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();


But he doesn't get through.
What could be the reason? Wrong Post parameters or cookies or something else? Can't figure it out on my own.

Headers like identical with the browser I transfer.

For some reason, my cookies have a different look than what the browser transmits ... Maybe this is the problem?

Here are the cookies that the browser sends:
PHPSESSID=JoHVf8NpzGf-uhyY8FXS91; cid=954932142; portal_tid=1355466714195-86254; portal_data=portal_tid=1355466714195-86254

And here are my cookies:
PHPSESSID=ssuvQVWUBcQqSlViFw-SE2; path=/,cid=308647358; expires=Sun, 14-Dec-2014 06:35:43 GMT; path=/

Why is that?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
ForhaxeD, 2012-12-14
@ForhaxeD

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.

S
Seganapa, 2012-12-15
@Seganapa

I sort of figured out one problem, it wasn’t enough

request.ServicePoint.Expect100Continue = false;

Now the question is about request.KeepAlive = true;
Why is the parameter passed normally in the first request, but is not displayed in the headers the second time, although I add this line?
And the second question:
The sniffer shows that if you use a regular browser, the line is added to the cookies:
portal_tid=1355502826904-62628
1355502826904 - this is how I understand unix time, but what is it - 62628 ?
What could it be I can't imagine? I will be glad for any help.
How to get 10 digit unix time I know:
Code:
int unixTime = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;

But how to get 13 digits? This is how I understood milliseconds or am I wrong?

T
trolostasik, 2012-12-15
@trolostasik

With questions like this, smoke better basics.

S
Seganapa, 2012-12-16
@Seganapa

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;

But what is this at the end, and did not understand ???
portal_tid= 1355502826904-62628

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question