Exemplo n.º 1
0
        /// <summary>
        /// Get the RSS feed via URL.
        /// /// </summary>
        /// <param name="feedUrl"></param>
        /// <returns></returns>
        public async Task <Feed> GetFeed(Uri feedUrl, int timeoutSeconds = 6)
        {
            Feed feed = null;

            using (var handler = new HttpClientHandler()) {
                handler.ClientCertificateOptions = ClientCertificateOption.Manual;
                handler.ServerCertificateCustomValidationCallback = (z, zz, zzz, zzzz) => { return(true); };
                using (HttpClient client = new HttpClient(handler)) {
                    client.DefaultRequestHeaders.Add("user-agent", "rss/1.0");
                    client.Timeout = TimeSpan.FromSeconds(timeoutSeconds);
                    using (var st = await client.GetStreamAsync(feedUrl.ToString())) {
                        using (var ms = new MemoryStream()) {
                            await st.CopyToAsync(ms);

                            feed = FeedReader.ReadFromByteArray(ms.ToArray());
                        }
                    }
                }
            }

            return(feed);
        }