示例#1
0
        /// <summary>
        /// GETs a byte array of data from the specified request URI string.
        /// </summary>
        /// <param name="requestUriString">The request URI string.</param>
        /// <param name="cookies">The cookies.</param>
        /// <param name="credentials">The Basic Authentication credentials.</param>
        /// <returns>A byte array of data from the specified request URI string.</returns>
        public static byte[] Get(string requestUriString, CookieContainer cookies, BasicAuthenticationCredentials credentials)
        {
            if (string.IsNullOrWhiteSpace(requestUriString))
            {
                throw new ArgumentNullException("requestUriString");
            }

            HttpWebResponse webResponse;

            return(Get(requestUriString, cookies, credentials, out webResponse));
        }
示例#2
0
        /// <summary>
        /// GETs a byte array of data from the specified request URI string.
        /// </summary>
        /// <param name="requestUriString">The request URI string.</param>
        /// <param name="cookies">The cookies.</param>
        /// <param name="credentials">The Basic Authentication credentials.</param>
        /// <param name="webResponse">The web response.</param>
        /// <returns>A byte array of data from the specified request URI string.</returns>
        public static byte[] Get(string requestUriString, CookieContainer cookies, BasicAuthenticationCredentials credentials, out HttpWebResponse webResponse)
        {
            if (string.IsNullOrWhiteSpace(requestUriString))
            {
                throw new ArgumentNullException("requestUriString");
            }

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestUriString);

            webRequest.Proxy           = WebRequest.DefaultWebProxy;
            webRequest.CookieContainer = cookies;
            webRequest.UserAgent       = m_UserAgent;
            if (credentials != null)
            {
                webRequest.Headers.Add(string.Format("Authorization: Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", credentials.UserName, credentials.Password)))));
            }
            webResponse = (HttpWebResponse)webRequest.GetResponse();

            byte[] data = new byte[256];
            using (Stream responseStream = webResponse.GetResponseStream())
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    int read;
                    do
                    {
                        read = responseStream.Read(data, 0, 256);
                        memoryStream.Write(data, 0, read);
                    } while (read > 0);

                    data = memoryStream.ToArray();
                }
            }

            return(data);
        }
示例#3
0
 /// <summary>
 /// GETs a byte array of data from the specified request URI string.
 /// </summary>
 /// <param name="requestUriString">The request URI string.</param>
 /// <param name="credentials">The Basic Authentication credentials.</param>
 /// <returns>A byte array of data from the specified request URI string.</returns>
 public static byte[] Get(string requestUriString, BasicAuthenticationCredentials credentials)
 {
     return(Get(requestUriString, cookies: null, credentials: credentials));
 }
示例#4
0
        /// <summary>
        /// GETs a byte array of data from the specified request URI string.
        /// </summary>
        /// <param name="requestUriString">The request URI string.</param>
        /// <param name="cookies">The cookies.</param>
        /// <param name="credentials">The Basic Authentication credentials.</param>
        /// <param name="webResponse">The web response.</param>
        /// <returns>A byte array of data from the specified request URI string.</returns>
        public static byte[] Get(string requestUriString, CookieContainer cookies, BasicAuthenticationCredentials credentials, out HttpWebResponse webResponse)
        {
            if (string.IsNullOrWhiteSpace(requestUriString))
                throw new ArgumentNullException("requestUriString");

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestUriString);
            webRequest.Proxy = WebRequest.DefaultWebProxy;
            webRequest.CookieContainer = cookies;
            webRequest.UserAgent = m_UserAgent;
            if (credentials != null)
            {
                webRequest.Headers.Add(string.Format("Authorization: Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", credentials.UserName, credentials.Password)))));
            }
            webResponse = (HttpWebResponse)webRequest.GetResponse();

            byte[] data = new byte[256];
            using (Stream responseStream = webResponse.GetResponseStream())
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    int read;
                    do
                    {
                        read = responseStream.Read(data, 0, 256);
                        memoryStream.Write(data, 0, read);
                    } while (read > 0);

                    data = memoryStream.ToArray();
                }
            }

            return data;
        }
示例#5
0
        /// <summary>
        /// GETs a byte array of data from the specified request URI string.
        /// </summary>
        /// <param name="requestUriString">The request URI string.</param>
        /// <param name="cookies">The cookies.</param>
        /// <param name="credentials">The Basic Authentication credentials.</param>
        /// <returns>A byte array of data from the specified request URI string.</returns>
        public static byte[] Get(string requestUriString, CookieContainer cookies, BasicAuthenticationCredentials credentials)
        {
            if (string.IsNullOrWhiteSpace(requestUriString))
                throw new ArgumentNullException("requestUriString");

            HttpWebResponse webResponse;
            return Get(requestUriString, cookies, credentials, out webResponse);
        }
示例#6
0
 /// <summary>
 /// GETs a byte array of data from the specified request URI string.
 /// </summary>
 /// <param name="requestUriString">The request URI string.</param>
 /// <param name="credentials">The Basic Authentication credentials.</param>
 /// <returns>A byte array of data from the specified request URI string.</returns>
 public static byte[] Get(string requestUriString, BasicAuthenticationCredentials credentials)
 {
     return Get(requestUriString, cookies: null, credentials: credentials);
 }