Exemple #1
0
        public static Image GetImage(string url, IMessage iLog)
        {
            HttpWebResponse res = null;

            try
            {
                res = (HttpWebResponse)WebGet._WebGet(url, iLog);
                if (!res.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ArgumentException(
                              string.Format(
                                  Properties.Resources.WebGetErrorException2,
                                  url,
                                  ((int)res.StatusCode).ToString()
                                  )
                              );
                }
                using (Stream ds = res.GetResponseStream())
                {
                    return((Image)Image.FromStream(ds));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (res != null)
                {
                    res.Close();
                }
            }
        }
Exemple #2
0
        public static string GetJsonString(string url, IMessage iLog)
        {
            HttpWebResponse res = null;

            try
            {
                res = (HttpWebResponse)WebGet._WebGet(url, iLog);
                using (Stream ds = res.GetResponseStream())
                {
                    using (StreamReader rd = new StreamReader(ds))
                    {
                        return(rd.ReadToEnd());
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (res != null)
                {
                    res.Close();
                }
            }
        }