예제 #1
0
 //--------------------------------------------------------------------------
 public string GetHashOfContens()
 {    //HTTPレスポンスのハッシュ値を返す
     try
     {
         HashAlgorithm HashFunc = SHA256Managed.Create();
         WebRequest    req      = WebRequest.Create(this.url);
         WebResponse   rsp      = req.GetResponse();
         Stream        stm      = rsp.GetResponseStream();
         byte[]        hash     = null;
         if (stm != null)
         {
             hash = HashFunc.ComputeHash(stm);
             BinaryReader reader = new BinaryReader(stm);
             reader.Close();
             stm.Close();
         }
         rsp.Close();
         StringBuilder sb = new StringBuilder();
         if (hash != null)
         {
             for (int i = 0; i < hash.Length; i++)
             {
                 sb.Append(hash[i].ToString("X2"));
             }
         }
         return(sb.ToString());
     }
     catch (WebException WebEx)
     {
         WebEx.ToString();
         return("");
     }
 }
예제 #2
0
        public override void WriteResult(Stream stream)
        {
            System.Net.HttpWebRequest ProxyRequest   = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(Url);
            System.Net.WebResponse    ServerResponse = null;
            if (!string.IsNullOrEmpty(this.Referrer))
            {
                ProxyRequest.Referer = this.Referrer;
            }

            /* Send the proxy request to the remote server or fail. */
            try
            {
                ServerResponse = ProxyRequest.GetResponse();
            }
            catch (System.Net.WebException WebEx)
            {
                new ErrorResult("Error: " + WebEx.ToString()).WriteResult(stream);
            }

            if (ServerResponse != null)
            {
                using (var instream = ServerResponse.GetResponseStream())
                {
                    try
                    {
                        // Copy with 512K Buffer
                        instream.CopyTo(stream, 524288);
                    }
                    catch (System.IO.IOException ioException)
                    {
                        // User probably canncelled
                        Console.WriteLine("IOException: {0}", ioException);
                    }
                    finally
                    {
                        instream.Close();
                    }
                }
            }
        }