?
Solved

VBScript: HttpRequest to a file

Posted on 2011-03-20
8
Medium Priority
?
761 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 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