熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C# 讓WebClient使用gzip編碼,並解壓

2013-11-13 09:50:34  來源: .NET編程 

  WebClient client = new WebClient()clientHeadersAdd(AcceptEncoding gzip deflatestring sUrl = byte[] byteArray = clientDownloadData(sUrl)

  // 處理 gzip string sContentEncoding = clientResponseHeaders[ContentEncoding]if (sContentEncoding == gzip

  { ToolClassLogMessage(gzip ok page)MemoryStream ms = new MemoryStream(byteArray)MemoryStream msTemp = new MemoryStream()int count = GZipStream gzip = new GZipStream(ms CompressionModeDecompress)byte[] buf = new byte[]

  while ((count = gzipRead(buf bufLength)) >

  { msTempWrite(buf count)}

  byteArray = msTempToArray()} // endgzip

  string sHtml = EncodingGetEncoding(GetString(byteArray)


From:http://tw.wingwit.com/Article/program/net/201311/11719.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.