예제 #1
0
        /// <summary>
        /// Downloads the page from the given URL
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        public XmlPage GetPage(Uri url)
        {
            XmlPage page;

            try
            {
                var request = WebRequest.Create(url);

                request.Method = "GET";
                request.Timeout = 90000;

                if (Context.RequireAuthentication)
                {
                    request.PreAuthenticate = true;

                    var authInfo = Context.Username + ":" + Context.Password;

                    authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));

                    request.Headers["Authorization"] = "Basic " + authInfo;
                }

                using (var response = request.GetResponse())
                {
                    using (var stream = response.GetResponseStream())
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            page = new XmlPage(url, reader.ReadToEnd());
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                throw new HudsonException(ex.Message);
            }

            return page;
        }
예제 #2
0
        public static XmlPage Load(string fileName)
        {
            var page = new XmlPage(new Uri("http://www.example.com/"), File.ReadAllText("../../xml/" + fileName));

            return page;
        }