Using VBScript to accept POST data



Hello,
I have a set of scripts that I would like to use to have my laptops "call" a
web server on a regular basis.

I would like to have the web server either host a VBS file, or an asp page
to which i can send an http POST request and then write the data to the web
servers disk.

My existing code looks like this.

The sendscript which creates the POST data
<code>
Option Explicit
Dim objShell, objScriptExec, a, strIpConfig, myvar
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("ipconfig /all")
strIpConfig = objScriptExec.StdOut.ReadAll
myvar = "send=" + strIpConfig

Do until 0=1 ' forever hopefully
On Error Resume Next
'a = IEPostBinaryRequest("http://192.168.1.1/cgi-bin/iistart2.asp";, myvar)
a=HTTPPost("http://192.168.1.1/cgi-bin/Laptop_locator_Reciever.vbs";, myvar)
WScript.Sleep 10000

Loop

Function HTTPPost(sUrl, sRequest)
dim oHTTP
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
</code>
The serverside
Something like this. I do not know how to accept POST data generated in the
first script into this script as an agrument, or any other way. Also can get
an asp page to accept data in the URL but not from my script.
<code>
'Laptop Locator Server Reciever
dim IpConfig, temp
'temp = 1
dim args
set args = WScript.Arguments
writeout(args(0))

Function WriteOut(IpString)
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strDirectory = "c:\inetpub\wwwroot\cgi-bin"
strFile = "\log.txt"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If

set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)

' Writes strText every time you run this VBScript
objTextFile.WriteLine(IpString)
objTextFile.Close

End Function
</code>
Thanks,
Chance


.



Relevant Pages

  • Re: Password Expire
    ... We have one fron end Edge server in our DMZ which passes email onto two ... I used to schedule a script to run every 24 hours on my Exchange 2003 ... Dim fso, txtarray, BodyText ... Call ProcessFolder (objContainer, numDays) ...
    (microsoft.public.exchange.admin)
  • Re: check disk space and email if above xx%?
    ... ' DriveSpace to HTM and email results VBS script ... 'This script will pull a listing of servers from (in this example, ... 'Additionally, in the summary and warning htm, each server has been ... Dim strComputer, Silent, strGBFree, strDiskFreeSpace, strDrvString ...
    (microsoft.public.scripting.vbscript)
  • Re: Array question...newbie programmer needs help!!!
    ... I am creating a script that appends excel files to an exisiting table. ... Dim dtmMostRecent As Date ... Dim strFile As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: VBscript in 2008 Server Task Scheduler will not run
    ... That means that yes, pointing directly to the script should work ok; it will probably default to the 64-bit version of the host IIRC, but that should be ok. ... In 2003 server and 2008 32 bit you can just point the task scheduler command ... > Dim mToday ... > For each inputData in input ...
    (microsoft.public.scripting.vbscript)
  • Re: Script taking longer than expected to complete: Consequences?
    ... If the user closes the browser window, the script will continue to run on ... Once the request is made to the server, ... > Dim sql ...
    (microsoft.public.inetserver.asp.general)

Loading