Zlib::DataError: incorrect header check

Zlib::DataError: incorrect header check

我有一个字符串,但我不知道编码类型

原始数据如下所示:

{
   "securityProxyResponseEnvelope":{
      "resultCode":"OK",
      "apiResponse":"{zlibe}9mtdE350h9rd4h7wlFX3AkeCtNsb40FFaEZAl/CfcNNKrhGXawhgAs2rI4rnEgIwLpgJkKl+qkB0kzJ6+ZFmmz12Pl9/9MPdA1unUKL5OdHcWmAZim3ZjDXFGCW4zruCS/IOSiU1qVKAF5qIbocB4+2rAF7zH18SRtmXM8YW3eYs5w1NPjmYkM31W8x7QvrKkzFscH3kqDwmYn0I2gNNOtfwuKjWd5snunyqxPopZHNX3CBdW/pj4+N0tJXjAoHorCe8Ypmjxnvh3zthkLTbiBLgeULH1hGvVtkI0C9PGMyt/92upVW6qHxqCYoO/LTJK1tq6OpBnMRBNZDDntSRkrzp+1RpvzbBxFtwQ9jh45eSthbG5hq+D2oJkW5zrGi6TM8eG4ztCqRoO9dEvz2JbQsDCTPz70+C6iPYdkvOyqji18ysLjBbGcHw1j45YItcurVxp0FChxXrnHZwu6m430xKEp7ONxvgEZurt3T8qAjrkrbHfd8jRjDydUXYsMoa",
      "session":"n3qp6jzHwZkXWSMW3VBF:jitqBjBmlZbrgcEgY7Od",
      "parameters":{

      }
   }
}

我想解压data['securityProxyResponseEnvelope']['apiResponse']中的字符串。

这是我正在做的事情:

@clear_string_from_data = '9mtdE350h9rd4h7wlFX3AkeCtNsb40FFaEZAl/CfcNNKrhGXawhgAs2rI4rnEgIwLpgJkKl+qkB0kzJ6+ZFmmz12Pl9/9MPdA1unUKL5OdHcWmAZim3ZjDXFGCW4zruCS/IOSiU1qVKAF5qIbocB4+2rAF7zH18SRtmXM8YW3eYs5w1NPjmYkM31W8x7QvrKkzFscH3kqDwmYn0I2gNNOtfwuKjWd5snunyqxPopZHNX3CBdW/pj4+N0tJXjAoHorCe8Ypmjxnvh3zthkLTbiBLgeULH1hGvVtkI0C9PGMyt/92upVW6qHxqCYoO/LTJK1tq6OpBnMRBNZDDntSRkrzp+1RpvzbBxFtwQ9jh45eSthbG5hq+D2oJkW5zrGi6TM8eG4ztCqRoO9dEvz2JbQsDCTPz70+C6iPYdkvOyqji18ysLjBbGcHw1j45YItcurVxp0FChxXrnHZwu6m430xKEp7ONxvgEZurt3T8qAjrkrbHfd8jRjDydUXYsMoa'

@decoded = Base64.decode64(@clear_string_from_data)
@inflated = Zlib::Inflate.inflate(@decoded)

但是这个returns

#=> Zlib::DataError: incorrect header check

这是什么原因造成的?接下来我可以尝试什么来解压缩数据?

是不是zlib数据造成的。你应该问问谁在生产原始数据。

我在尝试对未被 Zlib 缩小的数据调用 inflate 时遇到了这个问题。在我的例子中,它用于单元测试,我发送了一个纯字符串,只是忘记先在其上调用 .deflate 。

在你的情况下,如果你这样做,你不会收到错误:

@decoded = Zlib::Deflate.deflate(@clear_string_from_data) @inflated = Zlib::Inflate.inflate(@decoded)