Пример #1
0
 private static byte[] preprocess(byte[] bytes, MemoryStream memoryStream, NetWebClient.Encoding encoding, bool encrypt)
 {
     NetWebClient.clearStream(memoryStream);
     if (encoding != NetWebClient.Encoding.Deflate)
     {
         if (encoding != NetWebClient.Encoding.GZip)
         {
             memoryStream.Write(bytes, 0, bytes.Length);
         }
         else
         {
             using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress, true))
             {
                 gzipStream.Write(bytes, 0, bytes.Length);
             }
         }
     }
     else
     {
         uint num = NetWebClient.calcAdler32(bytes.LongLength, bytes);
         memoryStream.WriteByte(120);
         memoryStream.WriteByte(156);
         if (bytes.Length <= 128)
         {
             NetWebClient.deflateRawBlock(memoryStream, bytes, 0, bytes.Length);
         }
         else
         {
             using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true))
             {
                 deflateStream.Write(bytes, 0, bytes.Length);
             }
         }
         memoryStream.WriteByte((byte)(num >> 24 & 255U));
         memoryStream.WriteByte((byte)(num >> 16 & 255U));
         memoryStream.WriteByte((byte)(num >> 8 & 255U));
         memoryStream.WriteByte((byte)(num >> 0 & 255U));
     }
     if (encrypt)
     {
         memoryStream.Position = 0L;
         int num2 = (int)memoryStream.Length;
         int num3 = Cryptography.calcEncryptedSize(num2);
         NetWebClient.shared_.resizeTemporary(num3);
         byte[] tmp_ = NetWebClient.shared_.tmp_;
         memoryStream.Read(tmp_, 0, num3);
         Cryptography.padding(num2, tmp_);
         bytes = new byte[num3];
         Cryptography.Instance.encrypt(num3, bytes, num3, tmp_);
     }
     else
     {
         bytes = memoryStream.ToArray();
     }
     return(bytes);
 }
Пример #2
0
        private static void responseCallback(IAsyncResult asynchronousResult)
        {
            NetWebClient netWebClient = asynchronousResult.AsyncState as NetWebClient;

            try
            {
                HttpWebRequest httpWebRequest = netWebClient.request_;
                netWebClient.response_       = (httpWebRequest.EndGetResponse(asynchronousResult) as HttpWebResponse);
                netWebClient.responseStream_ = netWebClient.response_.GetResponseStream();
                NetWebClient.clearStream(NetWebClient.shared_.memoryStream_);
                netWebClient.responseStream_.BeginRead(NetWebClient.shared_.buffer_, 0, 1024, new AsyncCallback(NetWebClient.readCallback), netWebClient);
            }
            catch (WebException ex)
            {
                netWebClient.setError(ex.Status, ex.Message, 5, ex.Response as HttpWebResponse);
            }
            catch (Exception ex2)
            {
                netWebClient.setError(WebExceptionStatus.UnknownError, ex2.Message, 5, null);
            }
        }