Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Posting of XML messages

8 views
Skip to first unread message

Leon

unread,
Dec 11, 2009, 11:00:55 AM12/11/09
to
hello

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

Ruediger Roesler

unread,
Dec 15, 2009, 6:50:19 AM12/15/09
to
Leon <lvantoo...@hotmail.com> typed:

> 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

Leon

unread,
Dec 16, 2009, 4:55:01 PM12/16/09
to

"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
> .
>

Tom Lavedas

unread,
Dec 16, 2009, 5:52:13 PM12/16/09
to
On Dec 16, 4:55 pm, Leon <L...@discussions.microsoft.com> wrote:
> "Ruediger Roesler" wrote:
> > Leon <lvantoorenb...@hotmail.com> typed:

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

0 new messages