How to POST HTTPS request using VBScript

2020-06-18 09:15发布

问题:

I want to know how to make a HTTPS request from a VBScript client.

After receiving the request, how to decrypt the HTTPS response?

回答1:

HTTPS is not just an encryption format - it's a transport security protocol, with complex negotiation built-in. Just like you wouldn't try to build an HTTP client component in VBScript, similarly you wouldn't try to build an HTTPS/SSL client.

The VBScript language doesn't include any HTTP or HTTPS client, but windows has a couple of COM objects that can be used (from Windows Script Host of from ASP pages written in VBScript), and VBScript code running in internet explorer can similarly access a browser object that allows HTTPS calls.

From windows (WSH/ASP), the best object is typically MSXML2.ServerXmlHTTP, for example see this quick overview: http://www.developerfusion.com/article/3272/posting-form-data-to-a-web-page/2/

From Internet Explorer, as long as you're not dealing with legacy versions, the best idea is to use the cross-browser standard object XMLHttpRequest. The following page gives you an overview: http://www.jibbering.com/2002/4/httprequest.html

All of these HTTP clients also support HTTPS.



回答2:

dim xHttp: Set xHttp = createobject("MSXML2.ServerXMLHTTP")

xHttp.Open "GET", "https://yourhost.example.com/foo", False

' 2 stands for SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS
' 13056 means ignore all server side cert error
xHttp.setOption 2, 13056
xHttp.Send

' read response body
WScript.Echo xHttp.responseBody

Reference:

  • getOption Method of XML DOM
  • setOption Method of XML DOM