private byte[] InternalDecompress(byte[] bytes, bool useHeader, CompressionImplementation compressionImplementation) { switch (compressionImplementation) { case CompressionImplementation.ManagedZLib: return(ManagedZLib.Decompress(bytes, useHeader)); default: throw new ApplicationException(string.Format("Unknown compression implementation {0}", compressionImplementation)); } }
public static byte[] Compress(string unicodeString) { byte[] messagebytes = Encoding.Unicode.GetBytes(unicodeString); if (ConfigurationManager.AppSettings["UseManagedZLibForCompress"] == "true") { return(ManagedZLib.Compress(messagebytes, 6, true)); } else { return(MySpace.Common.IO.Compressor.GetInstance().Compress(messagebytes, true)); } }
public static string Decompress(byte[] compressedUnicodeString) { byte[] messagebytes = new byte[0]; if (ConfigurationManager.AppSettings["UseManagedZLibForDecompress"] == "true") { messagebytes = ManagedZLib.Decompress(compressedUnicodeString, true); } else { messagebytes = MySpace.Common.IO.Compressor.GetInstance().Decompress(compressedUnicodeString, true); } return(Encoding.Unicode.GetString(messagebytes)); }
public string GetHTTPData(string strformData, bool bNeedResponse) { string text = null; string requestUriString = "http://" + this.Server + "/ultima.do"; string s = strformData.Clone().ToString() + "&session=" + this.EncryptSession(true); byte[] bytes = new ASCIIEncoding().GetBytes(s); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUriString); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1))"; request.Referer = "http://df.36ji.uuzu.com/UltimaMain.swf"; request.Headers.Add("x-flash-version", "10,0,32,18"); request.CookieContainer = this._CookieContainer; request.AllowAutoRedirect = false; request.ContentLength = bytes.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { goto Label_029D; } this._ErrorCode = "SUCCESS"; if (response.Cookies.Count > 0) { this._CookieContainer.Add(response.Cookies); } if (!bNeedResponse) { goto Label_029D; } Stream responseStream = response.GetResponseStream(); if (response.ContentType.IndexOf("bin") != -1) { ManagedZLib.Initialize(); CompressionStream stream = new CompressionStream(responseStream, CompressionOptions.Decompress); try { text = new StreamReader(stream, Encoding.GetEncoding("UTF-8")).ReadToEnd(); text = text.Replace(@"\n", "\n"); text = text.Replace("\\\"", "\""); text = text.Replace("\"{", "{"); text = text.Replace("}\"", "}"); goto Label_01E8; } catch (ZLibException) { goto Label_01E8; } finally { stream.Close(); ManagedZLib.Terminate(); } } text = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8")).ReadToEnd(); Label_01E8: responseStream.Close(); if (text != null) { JsonObject obj2 = (JsonObject)JsonConvert.Import(text); if (obj2 != null) { obj2 = obj2["body"] as JsonObject; if ((obj2 != null) && (obj2["errcode"] != null)) { this._ErrorCode = obj2["errcode"].ToString(); if ((string.Compare(this._ErrorCode, "ERR_SESSION_000001", true) == 0) || (string.Compare(this._ErrorCode, "ERR_MAIN_000007", true) == 0)) { if (this.IsExpired()) { this._ErrorCode = "USER_EXPIRED"; } else { this.GetSession(); text = this.GetHTTPData(strformData, bNeedResponse); } } } } } else { this._ErrorCode = "NET_ERROR"; } Label_029D: response.Close(); } catch (WebException) { } return(text); }