dongqiu8375 2014-05-08 21:13
浏览 100
已采纳

与VB.NET类似的PHP GZIP压缩

I'm migrating a web service that was developed in VB.NET to PHP

I explain:

In VB. NET I have a method that compresses a single string with GZIP. ("Hello world!")

The method in the web service returns an array of bytes.

Then the array of bytes is received on a device with android, decompressed and converted to a string, this process works perfect.

the method in VB.NET, is this:

<WebMethod(Description:="GZIP Test")> _
Public Function GZIP() As Byte()
    Dim vTest As String = "Hello world!"

    Dim vBuffer1() As Byte = StrToByteArray(vTest)
    Dim vBuffer2() As Byte = Compress(vBuffer1)

    Return vBuffer2
End Function

Private Function StrToByteArray(ByVal str As String) As Byte()
    Dim encoding As New System.Text.UTF8Encoding()
    Return encoding.GetBytes(str)
End Function

Private Function Compress(ByVal Bits() As Byte) As Byte()
    On Error Resume Next
    Using ms As New MemoryStream(), zipMem As New GZipStream(ms, CompressionMode.Compress, True)
        zipMem.Write(Bits, 0, Bits.Length)
        zipMem.Close()

        Return ms.ToArray
    End Using
End Function

this method returns me the following value:

<base64Binary>H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Ir6dl2WVXlV1Oftd/x+VGYUbDAAAAA==</base64Binary>

I want PHP return me the SAME VALUE.

the tests I've done in PHP returns me the following.

function GZIP() {
      ob_start ( 'ob_gzhandler' );
      return base64_encode(gzdeflate('Hello world!', 9));
}

the value returned in PHP is:

80jNyclXKM8vyklRBAA=

Why ? There is an example that returns the same ?

Thanks in advance for all.

  • 写回答

2条回答 默认 最新

  • douruoshen1449 2014-05-08 21:23
    关注

    You are using the wrong de-/compression algorithm. Use phps gzcompress() and gzuncompress() instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号