LiveCodingChat.HtmlHelper.getSingleElement C# (CSharp) Метод

getSingleElement() публичный статический Метод

public static getSingleElement ( string data, string element ) : string
data string
element string
Результат string
        public static string getSingleElement(string data,string element)
        {
            int fInd = data.IndexOf (element);
            if (fInd == -1)
                return null;
            int eInd = data.IndexOf (">", fInd + element.Length);
            if (eInd == -1)
                eInd = data.Length - 1;
            return data.Substring (fInd, eInd - fInd+1);
        }

Usage Example

Пример #1
0
        private void LoginGithub(string username, string password, string data, ref CookieContainer cookies)
        {
            //POST login data
            Dictionary <string, string> postData = new Dictionary <string, string> ();
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://github.com/session");

            request.UserAgent       = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";
            request.CookieContainer = cookies;
            request.Method          = "POST";
            request.ContentType     = "application/x-www-form-urlencoded";

            postData.Add("utf8", "\u2713");
            postData.Add("authenticity_token", HtmlHelper.getAttribute(HtmlHelper.getSingleElement(data, "<input name=\"authenticity_token\""), "value"));
            postData.Add("login", username);
            postData.Add("password", password);
            postData.Add("return_to", HtmlHelper.getAttribute(HtmlHelper.getSingleElement(data, "<input id=\"return_to\" name=\"return_to\""), "value"));

            byte[] postBuild = HttpHelper.CreatePostData(postData);
            request.ContentLength = postBuild.Length;
            request.GetRequestStream().Write(postBuild, 0, postBuild.Length);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream())) {
                data = sr.ReadToEnd();
            }

            if (LoginCompleted != null)
            {
                LoginCompleted(this, new LoginEventArgs(data, cookies));
            }
        }
All Usage Examples Of LiveCodingChat.HtmlHelper::getSingleElement