/// <summary> /// 应用程序的主入口点。 /// </summary> //[STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // Console.WriteLine("Hello World"); //Console.WriteLine(Environment.Version.ToString()); string s = "阿斯个贷哈根室电话个撒谎干大事个贷伽师将阿斯个贷哈根室电话个撒谎干大事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将事个贷伽师将"; byte[] buffer = Encoding.UTF8.GetBytes(s); byte[] bytes; bytes = CompressHelper.GZipCompress ( buffer ); Console.WriteLine ( "{0},GZip: {1}; {2}" , buffer.Length , bytes.Length , s.Length ); //bytes = CompressHelper.ReadStreamToBytes(ms); //string ss = Encoding.UTF8.GetString(bytes); Stream ms = new MemoryStream(bytes); //ms.Write(bytes, 0, bytes.Length); ms.Position = 0; ms = CompressHelper.GZipDecompress ( ms ); bytes = StreamDataHelper.ReadDataToBytes(ms); string ss = Encoding.UTF8.GetString(bytes); Console.WriteLine(ss); bytes = CompressHelper.DeflateCompress ( buffer ); Console.WriteLine ( "{0},Deflate: {1}; {2}" , buffer.Length , bytes.Length , s.Length ); //Console.WriteLine("{0},Deflate: {1}", buffer.Length, bytes.Length); ss = Encoding.UTF8.GetString ( ( CompressHelper.DeflateDecompress ( bytes ) ) ); Console.WriteLine(ss); }
public void Post(string url) { var httpWebRequest = HttpWebRequest.Create(url); httpWebRequest.Method = "post"; httpWebRequest.ContentType = "application/json"; httpWebRequest.ContentLength = 0; byte[] buffer = null; using (WebResponse response = httpWebRequest.GetResponse()) { using (Stream stream = response.GetResponseStream()) { buffer = StreamDataHelper.ReadDataToBytes(stream); } } }
public T Get <T>(string url) { var httpWebRequest = HttpWebRequest.Create(url); byte[] buffer = null; using (WebResponse response = httpWebRequest.GetResponse()) { using (Stream stream = response.GetResponseStream()) { buffer = StreamDataHelper.ReadDataToBytes(stream); } } var json = Encoding.UTF8.GetString(buffer); T r = JsonConvert.DeserializeObject <T>(json); return(r); }