Example #1
0
        /// <summary>
        /// Avalik meetod andmete kättesaamiseks, tõmmatava aktsia sümbol pannakse paika konstruktoriga. 
        /// Siin meetodis toimub sisselogimise ettevalmistamine
        /// </summary>
        /// <param name="user">Kasutajanimi</param>
        /// <param name="psw">Parool</param>
        public void getData(string user, string psw)
        {
            _user = user;
            _password = psw;

            _webClientEx = new WebClientEx();
            _webClientEx.DownloadStringCompleted += client_DownloadStringCompleted;
            _webClientEx.DownloadStringAsync(new Uri("https://ycharts.com/login?next="));
        }
Example #2
0
        /// <summary>
        /// Sisselogimise lehelt leitakse serveri poolt seadistatud token ja kasutatakse seda sisselogimiseks.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void client_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {
            Regex rSector = new Regex("csrfmiddlewaretoken' value='(.*?)'");
            Match match = rSector.Match(e.Result);
            if (match.Success)
            {

                string token = match.Groups[1].Value;
                var data = new NameValueCollection
                               {
                                   {"csrfmiddlewaretoken", token},
                                   {"email", _user},
                                   {"password", _password},
                                   {"remember_me", "on"},
                                   {"next", "/"},
                                   {"auth_submit", "Sign In"},

                               };
                using (var clientA = _webClientEx.clone())
                {
                    clientA.Headers.Add("Referer: https://ycharts.com/login?next=");

                    clientA.UploadValuesCompleted += client_UploadValuesCompleted;
                    clientA.UploadValuesAsync(new Uri("https://ycharts.com/login"), data);
                    //clientA.UploadValues("https://ycharts.com/login", data);
                    _webClientEx = clientA.clone();
                    //clientA.DownloadStringCompleted += _webClientEx_DownloadStringCompleted;
                    //clientA.DownloadStringAsync(new Uri("https://ycharts.com/"));

                }

            }
        }
Example #3
0
 /// <summary>
 /// Kui sisselogimise andmed on saadetud, avatakse avaleht
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void client_UploadValuesCompleted(object sender, System.Net.UploadValuesCompletedEventArgs e)
 {
     using (var clientB = _webClientEx.clone())
     {
         clientB.DownloadStringCompleted += _webClientEx_DownloadStringCompleted;
         clientB.DownloadStringAsync(new Uri("https://ycharts.com/"));
         _webClientEx = clientB.clone();
     }
 }
Example #4
0
 public WebClientEx clone()
 {
     WebClientEx webClientEx = new WebClientEx();
     webClientEx._cookieContainer = this._cookieContainer;
     return webClientEx;
 }