?
Solved

Using XMLHTML in VBScript

Posted on 2003-03-17
4
Medium Priority
?
535 Views
Last Modified: 2011-09-20
I want to read an html document generated by another asp script and save it to an html file.

I have a button that calls a vbscript:

<input type="button" value="Save Modified File" name="B1" onclick="stroutputfile">

The VBscript:

<script language="vbscript">

   sub stroutputfile

      set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
      objXMLHTTP.Open "GET","http://localhost/amc3/display.asp",false
      objXMLHTTP.Send()

      set objFSO = createobject("scripting.Filesystemobject")
      set objTFN = objFSO.Createtextfile("c:\inetweb\wwwroot\amc3\test.Htm")

      objTFN.Write objXMLHTTP.ResponseText
   end sub
</script>

The problem seems to be getting the set statements right.  As it is here, I get an error:

     Object required: server

On the filesystem one I get:

     ActiveX component can't create object: 'scripting.Filesystemobject'

I have tried a lot of variations based on code samples I have found on EE, but nothing seems to work.

Thanks.
0
Comment
Question by:beauxdog
[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
  • 2
4 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 400 total points
ID: 8150893
Try this:

<html>
<head>
<script language="vbscript">

  sub stroutputfile
     set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
     objXMLHTTP.Open "GET","http://www.experts-exchange.com",false
     Call objXMLHTTP.Send()

     set objFSO = createobject("scripting.Filesystemobject")
     set objTFN = objFSO.Createtextfile("F:\Zvonko\tmp\ee.htm")
     objTFN.Write objXMLHTTP.ResponseText
     MsgBox "Saved: " & objXMLHTTP.ResponseText
  end sub
</script>
</head>
<body>
<form>
<input type="button" value="Save Modified File" name="B1" onclick="stroutputfile">
</form>
</body>
</html>

Good luck,
Zvonko

0
 

Author Comment

by:beauxdog
ID: 8154311
We are half way there.

I know I tried set objXMLHTTP = CreateObject("Microsoft.XMLHTTP") before, but I guess it only works when you say it.

set objFSO = createobject("scripting.Filesystemobject") returns an error:

ActiveX component can't create object: 'scripting.Filesystemobject'

This is the syntax I have seen in many examples.

I am using Windows 2000 Pro with IIS as my webserver.  I saw one suggestion that Windows Script Host needs to be installed.  I installed Windows Script Host 5.6 and it still doesn't work.

Thanks.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 8155084
Sorry, but I have tested this on Windows XP without problems.
Perhaps your security options are set to high.
My security options are set to ask for permission.

0
 

Expert Comment

by:jayme9
ID: 13447474
I'm attempting to use the XMLHTTP object as a way to add a page to my email.

example:

Finally able to send emails using the code below. However, in the Body of the email it doesn't contain my Confirmation.asp page, it contains: "Unable to establish Database Connection" Login failed for user '(Null)' Not associated with a trusted SQL Server connection.  
I did look at the MS article related to this issue and it doesn't help.  I am able to send database content to an email, but the minute I try to use the XMLHTTP object, it does not let me.
--------------------
Confirmation.asp is not a secure page. Why would it be asking to authenticate to the database with the implementation of the XMLHTTP object?

........
Mailer.Subject = "Visit request from TRACS"

Response.Buffer = True
Dim objXMLHTTP, xml

' Create an xmlhttp object:
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Or, for version 3.0 of XMLHTTP, use:
' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

' Opens the connection to the remote server.
xml.Open "GET", "http://localhost/TRACS/Confirmation.asp?travelrequest_no=EU-S-5061-42278", False

' Actually Sends the request and returns the data:
xml.Send
'Display the HTML both as HTML and as text
Mailer.Body = "The following task was submitted:<br><br>" & xml.responseText

Mailer.Send
set Mailer = Nothing
Set xml = Nothing
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 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