Внутренняя ошибка 500 при аутентификации http httpwebrequest C#
I tried to sign in using httpwebrequest C# but I have faced internal 500 error.. Here is the raw data that I copied with fiddler Please give me advice Thank you Source is private string login_autocafe() { string hidden_value = Get_hidden_value(); string url = "http://m.autocafe.co.kr/Home/CarmanagerLogin"; string sendData = "__RequestVerificationToken="+ hidden_value + "&MemberName=%EA%B3%B5%EC%A3%BC%EC%8B%9D&password=1234"; try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.Accept = "text/html, application/xhtml+xml, */*"; req.Referer = "http://m.autocafe.co.kr/Home/CarmanagerLogin"; req.Headers.Add("Accept-Language", "ko-KR"); req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"; req.ContentType = "application/x-www-form-urlencoded"; req.Headers.Add("Accept-Encoding", "gzip, deflate"); req.Host = "m.autocafe.co.kr"; req.Credentials = new NetworkCredential("%EA%B3%B5%EC%A3%BC%EC%8B%9D", "1234"); req.KeepAlive = true; req.Headers.Add("Pragma", "no-cache"); req.ServicePoint.Expect100Continue = false; req.CookieContainer = cookie; req.PreAuthenticate = true; StreamWriter writer = new StreamWriter(req.GetRequestStream()); writer.Write(sendData); writer.Close(); HttpWebResponse result = (HttpWebResponse)req.GetResponse(); Stream respStream = result.GetResponseStream(); string respStr = new StreamReader(respStream).ReadToEnd(); cookie.Add(result.Cookies); if (result.StatusCode == HttpStatusCode.OK) { return "Sucess"; } else { Console.WriteLine("Error"); return "ERR"; } } catch (WebException webex) { var pageContent = new StreamReader(webex.Response.GetResponseStream()).ReadToEnd(); // setText(txt_comtiz_result, webex.Message); return "ERR"; //MessageBox.Show(webex.Message); } } private string Get_hidden_value() { string hidden_value = ""; WebClient client = new WebClient(); string sourceUrl = client.DownloadString("http://m.autocafe.co.kr/Home/CarmanagerLogin"); HtmlAgilityPack.HtmlDocument mydoc = new HtmlAgilityPack.HtmlDocument(); mydoc.LoadHtml(sourceUrl); try { if (mydoc.DocumentNode != null) { string test = mydoc.DocumentNode.SelectSingleNode("/html/body/div/input").OuterHtml; hidden_value = mydoc.DocumentNode.SelectSingleNode("/html/body/div/input").Attributes["value"].Value; } } catch (Exception ex) { MessageBox.Show(ex.Message); } return hidden_value; } The data I got from fiddler is below POST http://m.autocafe.co.kr/Home/CarmanagerLogin HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Referer: http://m.autocafe.co.kr/Home/CarmanagerLogin Accept-Language: ko-KR User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate Host: m.autocafe.co.kr Content-Length: 188 Connection: Keep-Alive Pragma: no-cache Cookie: __RequestVerificationToken=CjXgwUkuIWXIhjtph9k092MXAsQQLHtCbO-UIZihHUvJOvQXXKc8o4v5l7oClEefzz9k5VHSvJwAZmdJAAZatHL9Eq1a1h73oJrr4--vCSg1 __RequestVerificationToken=1x5V8SIxdLtR7r7znbdyYu0MF5tG5spK3DweQOVl3Jw2Zr0ADHAEqmZZog5qjcIC8tssLgfTgov6_tzBWUEMWl2UND9e6ZFsCmUHOmtLraE1&MemberName=%EA%B3%B5%EC%A3%BC%EC%8B%9D&password=1234
Что я уже пробовал:
частная строка Get_hidden_value()
{
строка hidden_value = "";
WebClient client = новый WebClient();
строка sourceUrl = клиент.DownloadString("http://m.autocafe.co.kr/Home/CarmanagerLogin");
HtmlAgilityPack. HtmlDocument mydoc = новый HtmlAgilityPack.HtmlDocument();
мой друг.LoadHtml(sourceUrl);
пробовать
{
если (mydoc.DocumentNode != null)
{
string test = mydoc.DocumentNode.Метод selectsinglenode("/HTML-код/кузова/дел/вход").OuterHtml;
hidden_value = mydoc.DocumentNode.SelectSingleNode("/html/body/div / input").Значение атрибута"].Ценность;
}
}
поймать (исключение бывший)
{
Ящик для сообщений.Показать (например, сообщение);
}
вернуться hidden_value;
}
[no name]
Вы должны начать с этого примера : https://blogs.msdn.microsoft.com/ncl/2009/05/05/custom-http-authentication-schemes/