VBS gets the implementation code for GZIP-compressed HTTP content _vbs

Source: Internet
Author: User
Tags http request send cookies

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.