Esempio n. 1
0
        /// <summary>
        /// Gets a reader for the given URL.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static RssReadResults ReadRss(string url, HttpDownloadSettings settings = null)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (url.Length == 0)
            {
                throw new ArgumentOutOfRangeException("'url' is zero-length.");
            }

            // get...
            XmlDocument doc = HttpHelper.DownloadToXmlDocument(url, settings);

            if (doc == null)
            {
                throw new InvalidOperationException("doc is null.");
            }

            // defer...
            return(ReadRss(doc));
        }
Esempio n. 2
0
        private void buttonSendRequest_Click(object sender, EventArgs e)
        {
            try
            {
                string url = this.Url;
                if (string.IsNullOrEmpty(url))
                {
                    Alert.ShowWarning(this, "You must enter a URL.");
                    return;
                }

                // check...
                string lower = url.ToLower();
                if (!(lower.StartsWith("http://")) && !(lower.StartsWith("https://")))
                {
                    url = "http://" + url;
                    this.textUrl.Text = url;
                }

                // set...
                HttpDownloadSettings settings = new HttpDownloadSettings();
                settings.ExtraHeaders.Add("x-amx-apiusername", this.textApiUsername.Text.Trim());
                settings.ExtraHeaders.Add("x-amx-token", this.textToken.Text.Trim());
                XmlDocument doc = HttpHelper.DownloadToXmlDocument(url, settings);
                if (doc == null)
                    throw new InvalidOperationException("'doc' is null.");

                // show...
                this.ShowXml(doc);
            }
            catch (HttpDownloadException ex)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append(ex.InnerWebException);
                builder.Append("\r\n-----------------------------\r\n");
                try
                {
                    string error = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                    builder.Append(error);
                }
                catch
                {
                    builder.Append("(An error occurred whilst downloading error information)");
                }
                builder.Append("\r\n-----------------------------\r\n");
                builder.Append(ex);

                // show...
                this.ShowText(builder.ToString());
            }
            catch (Exception ex)
            {
                this.ShowText(ex.ToString());
            }
        }