Ejemplo n.º 1
0
        public Parameters()
        {
            InitializeComponent();
            Configuration currentConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (currentConfig.AppSettings.Settings["AppKey"] == null)
                currentConfig.AppSettings.Settings.Add(new KeyValueConfigurationElement("AppKey", ""));
            if (currentConfig.AppSettings.Settings["Token"] == null)
                currentConfig.AppSettings.Settings.Add(new KeyValueConfigurationElement("Token", ""));
            if (currentConfig.AppSettings.Settings["User"] == null)
                currentConfig.AppSettings.Settings.Add(new KeyValueConfigurationElement("User", ""));
            if (currentConfig.AppSettings.Settings["Password"] == null)
                currentConfig.AppSettings.Settings.Add(new KeyValueConfigurationElement("Password", ""));
            if (currentConfig.AppSettings.Settings["Domian"] == null)
                currentConfig.AppSettings.Settings.Add(new KeyValueConfigurationElement("Domian", ""));
            AppKey.Text = currentConfig.AppSettings.Settings["AppKey"].Value;
            Token.Text = currentConfig.AppSettings.Settings["Token"].Value;
            User.Text = currentConfig.AppSettings.Settings["User"].Value;
            if (currentConfig.AppSettings.Settings["Password"].Value != "")
            {
                Decryptor dec = new Decryptor(currentConfig.AppSettings.Settings["Password"].Value);
                Password.Text = dec.DescryptStr;
            }
            Domian.Text = currentConfig.AppSettings.Settings["Domian"].Value;
            currentConfig.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");

        }
Ejemplo n.º 2
0
 public string GET(string url, Encoding _encoding, Boolean needHeaders = false)
 {
     try
     {
         HttpWebRequest hwrq = CreateRequest(url);
         if (Environment.UserDomainName == "GRADIENT")
             hwrq.Credentials = CredentialCache.DefaultNetworkCredentials;
         else
         {
             Configuration currentConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
             Decryptor decryptor = new Decryptor(currentConfig.AppSettings.Settings["Password"].Value);
             hwrq.Credentials = new NetworkCredential(currentConfig.AppSettings.Settings["User"].Value, decryptor.DescryptStr, currentConfig.AppSettings.Settings["Domian"].Value);
         }
         hwrq.CookieContainer = Cookies;
         using (HttpWebResponse hwrs = (HttpWebResponse)hwrq.GetResponse())
         {
             Cookies.Add(hwrs.Cookies);
             using (StreamReader sr = new StreamReader(hwrs.GetResponseStream(), _encoding))
             {
                 if (needHeaders)
                     return hwrs.Headers.ToString() + sr.ReadToEnd().Trim();
                 else
                     return sr.ReadToEnd().Trim();
             }
         }
     }
     catch (Exception e)
     {
         return null;
     }
 }