Solved

VBScript: HttpRequest to a file

Posted on 2011-03-20
8
743 Views
Last Modified: 2012-05-11
Hi there,

I need to have a VBscript that sends an HttpRequest and dumps the text to a file.

This VBScript will be started from a batch file as the following command line:
cscript //nologo "WebsiteMonitor.vbs" "http://tools.oratory.com/altcodes.html" "WebsiteMonitor.txt"

The tools.oratory.com web page was use for test purposes only.

Here, as a result, the output file "WebsiteMonitor.txt", would contain the text (with the french accents) contained in tools.oratory.com/altcodes.html

Please provide a working script, not a references to make it work.

Thanks for your help,
Rene
0
Comment
Question by:ReneGe
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 35177749
Can you state the purpose can it be saved as html itself?
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35178355
Yes, it can be saved in HTML

Thanks,
Rene
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35178421
Try the following code...

for the html file to be created mention the full path

cscript //nologo "WebsiteMonitor.vbs" "http://tools.oratory.com/altcodes.html" "c:\WebsiteMonitor.html"
Set objArgs = WScript.Arguments
url=objargs(0)
html_file=objargs(1)

'***********************************************************************
On Error Resume Next

Dim xmlhttp : Set xmlhttp = CreateObject ("msxml2.xmlhttp.3.0")
xmlhttp.open "get", url, False
xmlhttp.send

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objfso.CreateTextFile html_file,True
    Set writefile= objfso.OpenTextFile(html_file,2)
    writefile.Write xmlhttp.responseText
    writefile.Close

'Clear all memory variables

Set xmlhttp = Nothing
Set objEmail= Nothing

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 35178996
The strange thing, is that it does not work with the test website I suggested. However, it works on all other websites I tested that contains french caracters.

So I googled "alt codes" and tried with other sites that displays alt codes. It did not work with any of these sites.

Could it be that "Alt Codes websites" contains "alt codes" that stops the script from working?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 12

Expert Comment

by:prashanthd
ID: 35179157
Try the following code

regards
Prashanth
Set objArgs = WScript.Arguments
url=objargs(0)
html_file=objargs(1)

'***********************************************************************
On Error Resume Next

Dim xmlhttp : Set xmlhttp = CreateObject ("msxml2.xmlhttp.3.0")
xmlhttp.open "get", url, False
xmlhttp.send

Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oXMLHTTP.responseBody
oStream.SaveToFile html_file
oStream.Close

'Clear all memory variables

Set xmlhttp = Nothing
Set objEmail= Nothing

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 35179217
Now, nothing is outputed to the files.
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 35179306
Typo error, replace line no 15 with following and test

oStream.Write xmlhttp.responseBody
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35180621
It works very well.

Thanks prashanthd!

Cheers,
Rene
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now