<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

VBA How To Decompress a Gzip Response From a HTTP Request

Published on
3,353 Points
353 Views
Last Modified:
There are times when I have encountered the need to decompress a response from a PHP request.
This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.

In this example, I needed to get a currency exchange rate for two currencies, in order to use them in an expense report. I am using MS Access and macros.


I've found a site where I can easily send the currency parameters I needed and the response was returned as a JSON structure, which is easy to manipulate. 


However, when I've checked the request (in WireShark), in order to use it in a macro function, I saw that the result was gibberish:

?      ?V*?-JNU?Rr

R?*I,JO-r=}??\?lpi.P?.
?Y?[?%??? 1P???????????B<l?T- ??Vu   



I then started to look for an idea of what might be the "problem". I needed the response data in plain text, much like a browser knows to show you when it performs the same request.


I saw a post about this here - MS Access VBA How To Decompress a Gzip Response From a HTTP Request and it got me thinking about the compression, since an "Accept-Encoding" header in the request has "gzip" as its value.


I looked for the possible values for the Accept-Encoding header and I leaned that in order to get the response as plain text, I needed to use deflate, as in the example below:

Accept-Encoding: identity, deflate

and not 

Accept-Encoding: identity, gzip;q=0


This tells the server to not use compress the response with gzip and instead to send me the plain text (or uncompressed, i.e. deflate) version of the response.


The reason the response is compressed is to be more efficient with bandwidth.  With larger datasets it may be necessary to deflate the response on the client if the uncompressed version is far larger than the compressed version.


Now, after modifying this header, I received the response I needed, which made it far easier to parse in my macro:

{"source":"EUR","target":"USD","sourceSum":"1","targetSum":3.9793,"rateDate":"01-06-2017","rateDateSet":"01-06-2017"}


It solved my problem and I hope it'll help all the others.


Have a great day,

Shai

0
Comment
Author:Shai Alon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Author Comment

by:Shai Alon
You're right, and I'm sorry.
I was frustrated from that post that it bothered me that the answer seemed simple.
I've modified the post to be neutral and answer the question only.

Regards,
Shai
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Join & Write a Comment

The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month