• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

Using XMLHTML in VBScript

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
beauxdog
Asked:
beauxdog
  • 2
1 Solution
 
ZvonkoSystems architectCommented:
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
 
beauxdogAuthor Commented:
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
 
ZvonkoSystems architectCommented:
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
 
jayme9Commented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now