Example #1
0
        /// <summary>
        /// Get viewstate from html by the id of the tag.
        /// </summary>
        /// <param name="siteContent">html result</param>
        /// <returns>HtmlClassModel</returns>
        public HtmlClassModel HtmlAgility(string siteContent)
        {
            var htmlclass = new HtmlClassModel();
            var doc       = new HtmlDocument();

            doc.LoadHtml(siteContent);

            foreach (var item in doc.DocumentNode.SelectNodes("//input").ToList())
            {
                HtmlAttribute att = item.Attributes["value"];
                if (att != null)
                {
                    if (att.OwnerNode.Id == "__VIEWSTATE")
                    {
                        htmlclass.__VIEWSTATE = att.Value;
                    }
                    else if (att.OwnerNode.Id == "__VIEWSTATEGENERATOR")
                    {
                        htmlclass.__VIEWSTATEGENERATOR = att.Value;
                    }
                    else if (att.OwnerNode.Id == "__EVENTVALIDATION")
                    {
                        htmlclass.__EVENTVALIDATION = att.Value;
                    }
                    else if (att.OwnerNode.Id == "Button1")
                    {
                        htmlclass.Button1 = att.Value;
                    }
                }
            }
            foreach (var imgItem in doc.DocumentNode.SelectNodes("//img").ToList())
            {
                HtmlAttribute att = imgItem.Attributes["src"];
                if (att != null)
                {
                    if (att.OwnerNode.Id == "Image1")
                    {
                        htmlclass.img = att.Value;
                        break;
                    }
                }
            }
            return(htmlclass);
        }
Example #2
0
        /// <summary>
        /// Create request to VR.ORG, get captcha link
        /// </summary>
        public void ConnectToVR()
        {
            string siteContent = string.Empty;

            IWebProxy webProxy = WebRequest.DefaultWebProxy;

            webProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(VRurl);

            request.Proxy = webProxy;
            if (cookieContainer == null)
            {
                cookieContainer         = new CookieContainer();
                request.CookieContainer = cookieContainer;
                Session["cookie"]       = cookieContainer;
            }
            var             html     = new HtmlClassModel();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            //For cookie testing
            int cookie = cookieContainer.Count;

            foreach (Cookie c in cookieContainer.GetCookies(request.RequestUri))
            {
                var r = ("Cookie['" + c.Name + "']: " + c.Value);
            }
            if (response.StatusCode == HttpStatusCode.OK)
            {
                using (Stream responseStream = response.GetResponseStream())               // Load the response stream
                    using (StreamReader streamReader = new StreamReader(responseStream))   // Load the stream reader to read the response
                    {
                        siteContent     = streamReader.ReadToEnd();
                        html            = HtmlAgility(siteContent);
                        Session["html"] = html;
                    }
            }
            TempData[Resource_GetTruck.captchaURL] = VRCaptchaURL + html.img;
        }