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条)

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化