![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Script to output single HTTP GET ? Hello, I'm looking a way to execute single http GET request using vbscript. The script will be run in wsh not in ASP. thanks Vilius |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Script to output single HTTP GET ? From: "Vilius Mockûnas" <v_mockunas@newsgroup> | Hello, | I'm looking a way to execute single http GET request using vbscript. | The script will be run in wsh not in ASP. | thanks | Vilius Why not incorporate a shell to the GNU WGET utility ? -- Dave http://www.claymania.com/removal-trojan-adware.html Multi-AV - http://www.pctipp.ch/downloads/dl/35905.asp |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Script to output single HTTP GET ? On Oct 7, 12:54*am, "Vilius Mockûnas" <v_mocku...@newsgroup> wrote: Quote: > Hello, > > I'm looking a way to execute single http GET request using vbscript. > The script will be run in wsh not in ASP. > > thanks > Vilius Get? Display the resulting page? Save the response? Is the expected response primarily text (HTNL) or binary (image)? The common method of issuing a GET from script is to access the scriptable MSXML.XMLHTTP class, something like the routine below, which uses a Get to retrieve and save an arbitrary URL (works for text or binary) to the named file. ' Source Michael Harris & Alex K. Angelopoulos ' modified by TGL May 2003 ' http://groups.google.com/groups?selm...40TK2MSFTNGP11 & ' http://www.google.com/groups?selm=%2...%40tkmsftngp05 Sub DownBinFile(FilePath, sURL) Const adTypeBinary = 1, adModeReadWrite = 3, adSaveCreateOverwrite = 2 ' Create an xmlhttp object: set oXML = CreateObject("MSXML2.XMLHTTP") oXML.open "GET", sURL, False oXML.send With CreateObject("ADODB.Stream") .type = adTypeBinary .mode = adModeReadWrite .open Do Until oXML.readyState = 4 : Wscript.Sleep 50 : loop .write oXML.responseBody .savetofile FilePath, adSaveCreateOverwrite End With End Sub Is that what you wanted? If not, please explain. _____________________ Tom Lavedas |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Script to output single HTTP GET ? Method using COM: 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 Or, a better approach, use AutoIt's InetGet() function. http://autoitscript.com "Vilius Mockûnas" wrote: Quote: > Hello, > > I'm looking a way to execute single http GET request using vbscript. > The script will be run in wsh not in ASP. > > thanks > Vilius > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Script to output single HTTP GET ? In addition to the other answers provided, if you want to do it more directly see here: www.jsware.net/jsware/scripts.php5#jshttp The XML method shown by Tom Lavedas is easier (assuming that you don't have ADODB disabled/removed). This download more like a scriptable interface for the Windows sockets API. It lets you handle the server "conversation" directly. Quote: > Hello, > > I'm looking a way to execute single http GET request using vbscript. > The script will be run in wsh not in ASP. > > thanks > Vilius > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Script to output single HTTP GET ? Tom Lavedas <tglbatch@newsgroup> typed: Quote: Quote: >> I'm looking a way to execute single http GET request using vbscript. >> The script will be run in wsh not in ASP. Quote: > The common method of issuing a GET from script is to access the > scriptable MSXML.XMLHTTP class, something like the routine below, > which uses a Get to retrieve and save an arbitrary URL (works for text > or binary) to the named file. > > ' Source Michael Harris & Alex K. Angelopoulos > ' modified by TGL May 2003 > ' http://groups.google.com/groups?selm...40TK2MSFTNGP11 > & > ' http://www.google.com/groups?selm=%2...%40tkmsftngp05 > > Sub DownBinFile(FilePath, sURL) > Const adTypeBinary = 1, adModeReadWrite = 3, adSaveCreateOverwrite = > 2 > ' Create an xmlhttp object: > set oXML = CreateObject("MSXML2.XMLHTTP") > oXML.open "GET", sURL, False > oXML.send > With CreateObject("ADODB.Stream") > .type = adTypeBinary > .mode = adModeReadWrite > .open > Do Until oXML.readyState = 4 : Wscript.Sleep 50 : loop > .write oXML.responseBody > .savetofile FilePath, adSaveCreateOverwrite > End With > End Sub if the "GlobalUserOffline" flag of the "Internet Settings" is set. That's why it is advisable to check the state of this flag every time before an online call to the http api is made. *IESample Registry Settings*: http://msdn.microsoft.com/en-us/library/aa908115.aspx Therefore, I have written an example script to demonstrate this. It downloads the application TCPView from SysInternals and executes it after unpacking. <!--######################### TCPView.wsf ############################# von h.r.roesler --> <job> <runtime> <description> Starts the TCPView utility from SysInternals. If it does not exist on the local system, it is downloaded from the internet. To show this message, enter: TCPIPLog.wsf /? </description> </runtime> <object id="fso" progid="Scripting.FileSystemObject"/> <object id="wshShell" progid="WScript.Shell"/> <object id="xmlHttpReq" progid="MSXML2.XMLHTTP.3.0"/> <object id="adoStream" progid="ADODB.Stream" reference="true"/> <resource id="URL"> http://download.sysinternals.com/Files/TCPView.zip</resource> <script language="VBScript"> Option Explicit Dim strFldr, strPath, strAppl strAppl = "TCPView.exe" strPath = wshShell.CurrentDirectory & ";" & _ fso.GetParentFolderName(WScript.ScriptFullName) & ";" & _ wshShell.Environment("PROCESS")("PATH") For Each strFldr In Split(strPath, ";") If Len(strFldr) > 0 Then If fso.FileExists(fso.BuildPath(strFldr, strAppl)) Then strAppl = fso.BuildPath(strFldr, strAppl) Exit For End If End If Next If Not(fso.FileExists(strAppl)) Then strAppl = GetAppl(strAppl) wshShell.Run strAppl Function GetAppl(strProg) Dim str, strDest Select Case wshShell.PopUp(strProg & " wasn't found. Do you " & _ "want it to download now?" & vbCRLF & _ getResource("URL"), 60, WScript.Scriptname & _ ": Request", vbYesNo Or vbQuestion Or vbSystemModal) Case vbNo Err.Raise vbObjectError + 2, , "Application was" & _ "not found: " & strProg Case Else str = wshShell.Environment("USER")("TEMP") str = wshShell.ExpandEnvironmentStrings(str) str = Download(getResource("URL"), str) End Select strDest = fso.GetParentFolderName(WScript.ScriptFullName) GetAppl = Unzip(str, strDest, strProg) End Function Function Download(strURL, strDstPath) Const CURVER = "HKCU\Software\Microsoft\Windows\CurrentVersion\" Const OFF = "Internet Settings\GlobalUserOffline", COMPLETED = 4 Dim intOffline strDstPath = fso.BuildPath(strDstPath, fso.GetFileName(strURL)) If Not(fso.FileExists(strDstPath)) Then intOffline = ReadReg(CURVER & OFF) If intOffline <> 0 Then wshShell.RegWrite CURVER & OFF, 0, "REG_DWORD" End If ' see <http://support.microsoft.com/kb/195730> xmlHttpReq.Open "GET", strURL, False xmlHttpReq.Send Do WScript.Sleep 50 Loop Until xmlHttpReq.ReadyState = COMPLETED With adoStream .Mode = adModeReadWrite .Type = adTypeBinary .Open .Write xmlHttpReq.ResponseBody .SaveToFile strDstPath, adSaveCreateNotExist .Close End With If ReadReg(CURVER & OFF) <> intOffline Then wshShell.RegWrite CURVER & OFF, intOffline, "REG_DWORD" End If End If Download = strDstPath End Function Function Unzip(strZipFldr, strDestFldr, strFile) Dim xpZipFolder, xpDstFolder With CreateObject("Shell.Application") Set xpZipFolder = .NameSpace(strZipFldr) Set xpDstFolder = .NameSpace(strDestFldr) xpDstFolder.CopyHere xpZipFolder.ParseName(strFile) End With Unzip = fso.BuildPath(strDestFldr, strFile) End Function Function ReadReg(ByRef strKey) On Error Resume Next ReadReg = wshShell.RegRead(strKey) End Function </script> </job> <!--######################### TCPView.wsf ##########################--> This is a reduced version of a little more extensive script which I have written before some time. However, this script encloses approximately 400 lines, so that it is a little bit too largely to publish it here. -- ЯR |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: script output | VB Script | |||
| Output XML to Single Line Log File using VBScript | VB Script | |||
| output group membership on a single line | PowerShell | |||
| BUG: All http access blocked after running Perl script | Vista networking & sharing | |||