i'm trying to create a vbscript that posts a xml file to a http
adres.
i googled my way arround and found something like this:
' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
can anyone supply me with a code so that i'm able to upload (post) a
xml file that is put on my disk and cold monitoring.xml
any help woukld be appriciated
Leon
> i'm trying to create a vbscript that posts a xml file to a http
> adres.
>
> i googled my way arround and found something like this:
>
> ' Create an HTTP object
> Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
>
> can anyone supply me with a code so that i'm able to upload (post) a
> xml file that is put on my disk and cold monitoring.xml
This is an example to upload a xmlfile to a website, it uses the XMLHTTP
Api instead:
<!--######################### PostXML.wsf #############################
von h.r.roesler -->
<package>
<job id="Upload">
<?job error="true" debug="true" ?>
<object id="wshShell" progid="WScript.Shell" reference=true/>
<object id="fso" progid="Scripting.FileSystemObject"
reference=true/>
<object id="xmlHttpReq" progid="MSXML2.XMLHTTP.3.0"/>
<object id="xmlDoc" progid="Msxml2.DOMDocument.3.0"/>
<script language="VBScript">
Option Explicit
Send "C:\monitoring.xml", "http://localhost/"
Sub Send(strFileName, strURL)
Const CURVER = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\"
Const IE = "Internet Settings\", OFF = "GlobalUserOffline"
Dim vtData, strFile, fsoStream
vtData = GetXML(strFileName)
Set strFile = fso.GetSpecialFolder(TemporaryFolder)
strFile = fso.BuildPath(strFile, "Response.html")
Set fsoStream = fso.OpenTextFile(strFile, ForWriting, True, vbTrue)
If wshShell.RegRead(CURVER & IE & OFF) <> 0 Then
wshShell.RegWrite CURVER & IE & OFF, 0, "REG_DWORD"
End If
With xmlHttpReq
.Open "POST", strURL & fso.GetFileName(strFileName), False
.SetRequestHeader "Content-Type", _
"application/x-www-form-urlencoded"
.Send vtData
fsoStream.Write .responseText
End With
fsoStream.Close
wshShell.Run strFile
End Sub
Function GetXML(strXMLFile)
xmlDoc.Async = False
xmlDoc.Load strXMLFile
If xmlDoc.ParseError.ErrorCode <> 0 Then
WScript.Echo "Helloho, here is " & xmlDoc.ParseError.Reason
WScript.Quit
End If
GetXML = xmlDoc.xml
End Function
</script>
</job>
</package>
<!--######################### PostXML.wsf ##########################-->
--
ЯR
"Ruediger Roesler" wrote:
i'm sorry
by vbsript i ment a .vbs file (wsh). so the code you supply looks nice but i
do not kown how to proces it.
do you have it in a wsh format
> .
>
Just save it as a WSF file. It will run under Wscript. It is just an
alternate way of packaging WSH scripts (in an XML format).
Or if it really must be done as a VBS, instantiate the objects with
CreateObject statements instead and remove the XML stuff ...
Option Explicit
Dim wshShell :set wshShell = createobject("WScript.Shell")
Dim fso : set fso = createobject("Scripting.FileSystemObject")
Dim xmlHttpReq : set xmlHttpReq = createobject("MSXML2.XMLHTTP.3.0")
Dim xmlDoc : set xmlDoc = createobject("Msxml2.DOMDocument.3.0")
vtData = GetXML(strFileName)
That should about do it.
_____________________
Tom Lavedas