Не могу опубликовать запрос на вход - PullRequest
0 голосов
/ 29 августа 2018

Я пытаюсь зайти на сайт. Я использую httpwebrequest для параметров входа в систему, а затем пытаюсь получить исходный код новой страницы. Но он выдает «Bad Request» ;. Где ошибка в моем коде?

string formUrl = "https://tr.ogame.gameforge.com:443/main/login"; // NOTE: This is the URL the form POSTs to, not the URL of the form (you can find this in the "action" attribute of the HTML's form tag
        string formParams = string.Format("credentials[email]={0}&credentials[password]={1}&autologin={2}&language={3}&kid={4}", "myUsername", "myPassword","false","tr","");
        string cookieHeader;
        WebRequest req = WebRequest.Create(formUrl);
        req.ContentType = "application/x-www-form-urlencoded";
        req.Method = "POST";
        byte[] bytes = Encoding.ASCII.GetBytes(formParams);
        req.ContentLength = bytes.Length;
        using (Stream os = req.GetRequestStream())
        {
            os.Write(bytes, 0, bytes.Length);
        }
        WebResponse resp = req.GetResponse();
        cookieHeader = resp.Headers["Set-cookie"];
        using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
        {
            string pageSource = sr.ReadToEnd();
            txtb.Text = pageSource;
        }

Вот результат, который я получу;

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>400 Bad Request</title>
    </head><body>
    <h1>Bad Request</h1>
    <p>The request could not be understood by the server.</p>
    </body></html>

Вот заголовки запроса веб-страницы; Снимок экрана1 Снимок экрана2

...