Переписать VB скрипт на C# - C# (232480)
Формулировка задачи:
Здравствуйте, есть скрип на VB, но мне нужно его переписать на C#, сам я в VB, увы, 0. Может поможет кто переписать?
Скрипт:
Dim o, WFLogin, WFPassword, WFToken, WFUid, WFSessionKey, WFPersId, WFKey, wsh WFLogin = "login" WFPassword = "password" Set o = CreateObject("Microsoft.XMLHTTP") o.open "POST", "https://authdl.mail.ru/ec.php?hint=GcAuth", False o.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" o.setRequestHeader "Content-Length", Len("<?xml version=""1.0"" encoding=""UTF-8""?><GcAuth Username="""&WFLogin&""" Password="""&WFPassword&""" ChannelId=""0""/>") o.setRequestHeader "User-Agent","Downloader/4300" o.send "<?xml version=""1.0"" encoding=""UTF-8""?><GcAuth Username="""&WFLogin&""" Password="""&WFPassword&""" ChannelId=""0""/>" Set xmlParser = CreateObject("Msxml2.DOMDocument") xmlParser.loadXML(o.responsetext) WFToken = xmlParser.getElementsByTagName("GcAuth").Item(0).getAttribute("Token") WFUid = xmlParser.getElementsByTagName("GcAuth").Item(0).getAttribute("Uid") WFSessionKey = xmlParser.getElementsByTagName("GcAuth").Item(0).getAttribute("SessionKey") o.open "POST", "https://authdl.mail.ru/ec.php?hint=EnazaGetOrdersList", False o.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" o.setRequestHeader "Content-Length", Len("<?xml version=""1.0"" encoding=""UTF-8""?><EnazaGetOrdersList Uid="""&WFUid&""" SessionKey="""&WFSessionKey&""" UidType=""3""/>") o.setRequestHeader "User-Agent","Downloader/4300" o.send "<?xml version=""1.0"" encoding=""UTF-8""?><EnazaGetOrdersList Uid="""&WFUid&""" SessionKey="""&WFSessionKey&""" UidType=""3""/>" o.open "POST", "https://authdl.mail.ru/sz.php?hint=AutoLogin", False o.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" o.setRequestHeader "Content-Length", Len("<?xml version=""1.0"" encoding=""UTF-8""?><AutoLogin ProjectId=""1177"" SubProjectId=""0"" ShardId=""1"" GcToken="""&WFToken&"""/>") o.setRequestHeader "User-Agent","Downloader/4300" o.send "<?xml version=""1.0"" encoding=""UTF-8""?><AutoLogin ProjectId=""1177"" SubProjectId=""0"" ShardId=""1"" GcToken="""&WFToken&"""/>" xmlParser.loadXML(o.responsetext) WFPersid = xmlParser.getElementsByTagName("AutoLogin").Item(0).getAttribute("PersId") WFKey = xmlParser.getElementsByTagName("AutoLogin").Item(0).getAttribute("Key") Set wsh = WScript.CreateObject("WScript.Shell") wsh.Exec("Game.exe --shard_id=0 +online_server s0.warface.ru -uid "&WFPersid&" -token "&WFKey&" ")
Решение задачи: «Переписать VB скрипт на C#»
textual
Листинг программы
string SendRequest(string url, string content) { string result; HttpWebRequest o = (HttpWebRequest)WebRequest.Create(url); o.Method = "POST"; o.ContentType = "application/x-www-form-urlencoded"; o.ContentLength = content.Length; o.UserAgent = "Downloader/4300"; byte[] bytes = Encoding.UTF8.GetBytes(content); var reqstream = o.GetRequestStream(); reqstream.Write(bytes, 0, bytes.Length); reqstream.Close(); var response = o.GetResponse(); using (Stream respstream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(respstream)) { result = reader.ReadToEnd(); } } return result; } void StartGame(string login, string password) { string WFLogin = login, WFPassword = password, WFToken, WFUid, WFSessionKey, WFPersId, WFKey; string content = $@"<?xml version=""1.0"" encoding=""UTF-8""?><GcAuth Username=""{WFLogin}"" Password=""{ WFPassword }"" ChannelId=""0""/>"; XDocument xdoc = XDocument.Parse(SendRequest(@"https://authdl.mail.ru/ec.php?hint=GcAuth", content)); XElement GcAuth = xdoc.Element("GcAuth"); WFToken = GcAuth.Attribute("Token").Value; WFUid = GcAuth.Attribute("Uid").Value; WFSessionKey = GcAuth.Attribute("WFSessionKey").Value; content = $@"<?xml version=""1.0"" encoding=""UTF-8""?><EnazaGetOrdersList Uid=""{ WFUid }"" SessionKey=""{ WFSessionKey }"" UidType=""3""/>"; SendRequest(@"https://authdl.mail.ru/ec.php?hint=EnazaGetOrdersList", content); content = $@"<?xml version=""1.0"" encoding=""UTF-8""?><AutoLogin ProjectId=""1177"" SubProjectId=""0"" ShardId=""1"" GcToken=""{ WFToken }""/>"; xdoc = XDocument.Parse(SendRequest(@"https://authdl.mail.ru/sz.php?hint=AutoLogin", content)); XElement AutoLogin = xdoc.Element("AutoLogin"); WFPersId = AutoLogin.Attribute("PersId").Value; WFKey = AutoLogin.Attribute("Key").Value; Process.Start("Game.exe", $"--shard_id=0 +online_server s0.warface.ru -uid { WFPersId } -token { WFKey } "); }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д