Using VBScript to accept POST data
- From: "Chance" <cfulton@xxxxxxxxxxxxxxxx>
- Date: Tue, 22 Aug 2006 13:05:22 -0400
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
.
- Prev by Date: Re: How to check registry value with IF statement?
- Next by Date: Re: Reading/Writing Text File
- Previous by thread: delete contents of desktop folder
- Next by thread: List domains and servers by domains
- Index(es):
Relevant Pages
|
Loading