Solved

VBScript: HttpRequest to a file

Posted on 2011-03-20
8
755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

695 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