Many web sites to improve load speed, enable the HTTP server gzip compression, when the client sent an HTTP request in the declaration can accept gzip encoding, the server automatically to the HTTP response content for gzip compression. However, it is not so easy to automatically decompress the gzip encoding in the VBS.
Different components for GZIP compression processing is not the same, first look at the msxml2.xmlhttp:
' By Demon
' http://demon.tw
Dim http
Set http = CreateObject ("Msxml2.xmlhttp")
Http.open "Get", "https ://www.baidu.com ", False
Http.setrequestheader" accept-encoding "," gzip "
http.send
WScript.Echo Http.responsetext
From the test results, Msxml2.xmlhttp will automatically gzip decompression, good!
The second is msxml2.serverxmlhttp:
' by Demon
Dim http
Set http = CreateObject ("Msxml2.serverxmlhttp")
Http.open "Get", "https:// Www.baidu.com ", False
Http.setrequestheader" accept-encoding "," gzip "
http.send
WScript.Echo Http.responsetext
Unfortunately, the return is garbled. And look at winhttp.winhttprequest.5.1:
' by Demon
Dim http
Set http = CreateObject ("winhttp.winhttprequest.5.1")
Http.open "Get", "https:// Www.baidu.com ", False
Http.setrequestheader" accept-encoding "," gzip "
http.send
WScript.Echo Http.responsetext
is still garbled. Although the general use of msxml2.xmlhttp components is more than enough, but sometimes not, such as the inability to send cookies, can not forge referer and so on. So we still have to find a way to decode gzip, there are no more than two, their own use of VBS to write algorithms or call the Third-party components.
Algorithm I am lazy not to write, feel less efficient, which friend interested can write to play. Found a nice third party component (I'm old enough to use a third party) Chilkat.gzip:
Dim Gzip
Set gzip = CreateObject ("Chilkat.gzip")
gzip.unlockcomponent "" by
Demon
Dim http
Set http = CreateObject ("winhttp.winhttprequest.5.1")
Http.open "Get", "https://www.baidu.com", False
Http.setrequestheader "accept-encoding", "gzip"
http.send
WScript.Echo gzip.uncompressstring ( Http.responsebody, "Utf-8")
By the way, this component is charged, can be free to try for 30 days, so still should use VBS to achieve?
Original: http://demon.tw/programming/vbs-http-gzip.html