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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀