Exemple #1
0
        public Bitmap DownloadFile(string url, string refer)
        {
            HttpWebRequest request = CreateRequest(url, refer);
            Stream         responseStream;
            Bitmap         bitmap = null;

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    responseStream = response.Headers.Get("Content-Encoding") != null ?
                                     new GZipStream(response.GetResponseStream(), CompressionMode.Decompress)
                        : response.GetResponseStream();
                    if (responseStream != null)
                    {
                        bitmap = (Bitmap)Image.FromStream(responseStream);
                    }
                    if (!string.IsNullOrEmpty(ResponseHeaderData))
                    {
                        ResponseHeaderData = response.Headers.Get(ResponseHeaderData);
                    }
                }
            }
            catch (Exception ex)
            {
                LogerDAL.WriteLog(ex);
                return(null);
            }
            return(bitmap);
        }
Exemple #2
0
        /// <summary>
        ///     发送请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="refer"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Post2(string url, string refer, string data)
        {
            byte[]          bytes = Encoder.GetBytes(data);
            string          str;
            HttpWebResponse response = null;
            StreamReader    reader;
            Stream          stream;

            try
            {
                using (response = (HttpWebResponse)CreatePostRequest2(url, refer, bytes).GetResponse())
                {
                    if (response.Headers.Get("Content-Encoding") != null)
                    {
                        stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
                        reader = new StreamReader(stream, Encoder);
                    }
                    else
                    {
                        reader = new StreamReader(response.GetResponseStream(), Encoder);
                    }
                    str = reader.ReadToEnd();
                    if (!string.IsNullOrEmpty(ResponseHeaderData))
                    {
                        ResponseHeaderData = response.Headers.Get(ResponseHeaderData);
                    }
                }
                return(str);
            }
            catch (Exception ex)
            {
                LogerDAL.WriteLog(ex);
                return(string.Empty);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }