HTTP GET and POST using VBscript

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

HTTP GET and POST using VBscript

Post by Marcus Tettmar » Mon Feb 07, 2005 2:26 pm

Here are a couple of functions using two different methods that you can use to POST data to a web page or XML document and retrieve data using a GET operation.

The XMLHTTP object is extremely powerful and can be used to parse XML documents as well as GET and POST data. For more info please see:
http://msdn.microsoft.com/library/en-us ... mscXML.asp


VBSTART
Function HTTPPost(sUrl, sRequest)
set oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.open "POST", sUrl,false
oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHTTP.setRequestHeader "Content-Length", Len(sRequest)
oHTTP.send sRequest
HTTPPost = oHTTP.responseText
End Function

Function HTTPGet(URL)
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate URL
do while IE.Busy
loop
HTTPGet = IE.document.documentelement.outerhtml
IE.quit
Set IE = Nothing
End Function
VBEND
VBEval>HTTPGet("http://www.mjtnet.com/contact.htm"),HTMLResult
VBEval>HTTPPost("http://www.mjtnet.com/contact.htm","sen ... eplace.com"),HTMLResult2

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts