[Ruby FAQs] Exception: Zlib::DataError: unknown compression method when use rest-client post data to WeChat Pay Unifiedorder API
Exception: Zlib::DataError: unknown compression method
Recently encountered a problem when we used rest-client
, faraday
gem or other HTTP client libraries to post data to WeChat Pay Unifiedorder API - https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1.
1 | url = "https://api.mch.weixin.qq.com/pay/unifiedorder" |
Downgrade rest-client
version to 2.0.2 in Gemfile
, then run bundle update
to update Gemfile.lock
1 | Gemfile |
Or set Header Accept-Encoding
to identity
before post data. ruby - Why am I getting Zlib::DataError? - Stack Overflow - https://stackoverflow.com/questions/37926803/why-am-i-getting-zlibdataerror
1 | result = RestClient.post(url, data, { 'Accept-Encoding' => 'identity'}) |
References
[2] rest-client | RubyGems.org | your community gem host - https://rubygems.org/gems/rest-client