示例#1
0
        static public async Task <string> HTTPDownload(Uri ResourceURI)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Combine(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback((object s, X509Certificate cert, X509Chain ch, SslPolicyErrors sec) => true));
            ServicePointManager.DefaultConnectionLimit = 50;
            CookieContainer cookieContainer = new CookieContainer();
            HttpWebRequest  httpRequest     = WebRequest.CreateHttp(ResourceURI);

            try
            {
                httpRequest.CookieContainer                = cookieContainer;
                httpRequest.Timeout                        = (int)TimeSpan.FromSeconds(15.0).TotalMilliseconds;
                httpRequest.AllowAutoRedirect              = true;
                httpRequest.AutomaticDecompression         = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
                httpRequest.ServicePoint.Expect100Continue = false;
                httpRequest.UserAgent                      = "Mozilla / 5.0(Windows NT 6.1; WOW32; Trident / 7.0; rv: 11.0) like Gecko";
                httpRequest.Accept = "ext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                httpRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate;q=0.8");
                httpRequest.Headers.Add(HttpRequestHeader.CacheControl, "no-cache");

                return(new StreamReader(
                           (await httpRequest.GetResponseAsync()).GetResponseStream()
                           ).ReadToEnd());
            }

            catch (Exception ex)
            {
                await Program.LogAsync(new LogMessage(LogSeverity.Error, nameof(HTTPDownload) + ": ", ex.Message, ex));
            }
            return("");
        }
示例#2
0
        public async Task DolAsync([Remainder] string num = "1")
        {
            try
            {
                HtmlNode tbody = await SiteWorker.ParseSite();

                double init = double.Parse(num.Replace('.', ','));
                await Context.Channel.SendMessageAsync(DolAsync(tbody, init, "UAH")
                                                       + '\n' + DolAsync(tbody, init, "RUB")
                                                       + '\n' + DolAsync(tbody, init, "BYN")
                                                       + '\n' + DolAsync(tbody, init, "CNY")
                                                       + '\n' + DolAsync(tbody, init, "EUR"),
                                                       false, null, null);

                return;
            }
            catch (Exception ex)
            {
                await Program.LogAsync(new LogMessage(LogSeverity.Error, nameof(DolAsync), ex.Message, ex));
            }
        }