KeithMcElroy
asked on
Why does this use of htmlfile object not work in classic asp
doc.write htmlFile.ReadAll causes http err 500, why?
This works in local vbscript, the fso part works ( I can response.write that part without err)
I opened up permissions.
Thanks,
Here is the html file http://pswf.net/w/test.html
Here is the url: http://pswf.net/w/w.asp
Here is the code
Dim doc, objFSO, htmlfile
Set doc = Server.CreateObject("HTMLF ILE")
Set objFSO = Server.CreateObject("Scrip ting.FileS ystemObjec t")
set htmlFile= objFSO.OpenTextFile(Server .MapPath(" test.html" ))
doc.write htmlFile.ReadAll
'Response.Write doc.documentElement.outerH TML
set htmlFile = nothing
set doc = nothing
set objFSO = nothing
This works in local vbscript, the fso part works ( I can response.write that part without err)
I opened up permissions.
Thanks,
Here is the html file http://pswf.net/w/test.html
Here is the url: http://pswf.net/w/w.asp
Here is the code
Dim doc, objFSO, htmlfile
Set doc = Server.CreateObject("HTMLF
Set objFSO = Server.CreateObject("Scrip
set htmlFile= objFSO.OpenTextFile(Server
doc.write htmlFile.ReadAll
'Response.Write doc.documentElement.outerH
set htmlFile = nothing
set doc = nothing
set objFSO = nothing
ASKER
I did the second item, looking for the first
http://screencast.com/t/f5on2Vxwhwdi
http://screencast.com/t/f5on2Vxwhwdi
I tested this and it is failing at your server.createObject("HTMLF ILE")
Try this instead
Try this instead
<%
dim sFileText
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.OpenTextFile( Server.MapPath( "test.html" ) )
sFileText = oFile.ReadAll
reponse.write sFile
oFile.Close
Set oFile = nothing
set oFSO = nothing
%>
>I did the second item, looking for the first
Keith, if you surf while logged into your server you can see the exact error.
Keith, if you surf while logged into your server you can see the exact error.
ASKER
I see what you mean, do it all on the server
Here is what I got
http://screencast.com/t/azYYQeu2U
Line 12 is hdoc.write htmlFile.ReadAll
Here is what I got
http://screencast.com/t/azYYQeu2U
Line 12 is hdoc.write htmlFile.ReadAll
ASKER
When I response.write htmlFile.ReadAll it presents the html.
So, hdoc.write is the part that appears to not be working. Stumped!
So, hdoc.write is the part that appears to not be working. Stumped!
I don't believe there is a doc.write in asp/vb. You can response.write to the screen. Or you can stream a text file to the server via fso.
is hdoc a typo in your last 2 posts? in your code you have the object just as doc
while this doesn't explain the WHY on why your page is failing, here is an alternative you may want to consider, as this will allow you to capture ANY web page:
<%
url = "http://www.espn.com/main.html"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
Response.write xmlhttp.responseText
set xmlhttp = nothing
%>
Had to double check myself.... document.write would be if you are using asp/jscript.
document.write for jscript you have doc.write
scott - I believe the OP is using vbscript as defined by his first line when he is DIM-ing his variables
ASKER
the htmlfile object is needed so I can traverse and manipulate the dom
I believe someone tested this on another server and it worked.
Something about this server? This is a virtual private server hosted by jodohost.
Dim hdoc, objFSO, htmlfile
Set hdoc = Server.CreateObject("HTMLF ILE")
Set objFSO = Server.CreateObject("Scrip ting.FileS ystemObjec t")
set htmlFile = objFSO.OpenTextFile("c:\in etpub\wwwr oot\pswf_n et\w\test. html")
hdoc.write htmlFile.ReadAll <<< point of failure
'Response.Write hdoc.documentElement.outer HTML
set htmlFile = nothing
set hdoc = nothing
set objFSO = nothing
I believe someone tested this on another server and it worked.
Something about this server? This is a virtual private server hosted by jodohost.
Dim hdoc, objFSO, htmlfile
Set hdoc = Server.CreateObject("HTMLF
Set objFSO = Server.CreateObject("Scrip
set htmlFile = objFSO.OpenTextFile("c:\in
hdoc.write htmlFile.ReadAll <<< point of failure
'Response.Write hdoc.documentElement.outer
set htmlFile = nothing
set hdoc = nothing
set objFSO = nothing
That's what I thought.
What is the end result you are after. Because the option I gave you works.
If you want to read an xml file, you can read it just as like making a soap call and reading the response. You can use some form of CreateObject("MSXML2.DOMDo cument.3.0 ")
https://www.experts-exchange.com/questions/28293687/Classic-ASP-and-SOAP.html?anchorAnswerId=39646834#a39646834
What is the end result you are after. Because the option I gave you works.
If you want to read an xml file, you can read it just as like making a soap call and reading the response. You can use some form of CreateObject("MSXML2.DOMDo
https://www.experts-exchange.com/questions/28293687/Classic-ASP-and-SOAP.html?anchorAnswerId=39646834#a39646834
' get the response
dim getCustPayMethText
getCustPayMethText=strResult
Set objReturn = CreateObject("MSXML2.DOMDocument.3.0")
objReturn.loadXML objXMLHTTP.responseText
' parse the response
if not objReturn.getElementsByTagName("TransactionsMatched").Item(0) is Nothing then
TransactionsMatched= objReturn.getElementsByTagName("TransactionsMatched").Item(0).text
else
TransactionsMatched="0"
end if
if cdbl(TransactionsMatched)>0 then
for x = 0 to cint(TransactionsMatched)-1
if not objReturn.getElementsByTagName("RefNum").Item(x) is Nothing then
RefNum= objReturn.getElementsByTagName("RefNum").Item(x).text
else
RefNum="N/A"
end if
if not objReturn.getElementsByTagName("Result").Item(x) is Nothing then
Result= objReturn.getElementsByTagName("Result").Item(x).text
else
Result="N/A"
end if
if not objReturn.getElementsByTagName("ResultCode").Item(x) is Nothing then
ResultCode= objReturn.getElementsByTagName("ResultCode").Item(x).text
else
ResultCode="N/A"
end if
if not objReturn.getElementsByTagName("CardNumber").Item(x) is Nothing then
CardNumber= objReturn.getElementsByTagName("CardNumber").Item(x).text
else
CardNumber="NA/A"
end if
if not objReturn.getElementsByTagName("TransactionType").Item(x) is Nothing then
TransactionType= objReturn.getElementsByTagName("TransactionType").Item(x).text
else
TransactionType="0"
end if
searchTransactions="TransactionsMatched,"&"RefNum,"&"Result,"&"ResultCode,"&"CardNumber,"&"TransactionType"&
end Function
looks like it IS the server, I just ran a quick test on my site and it worked:
http://www.exchangetree.org/test.asp
pulling data from http://www.exchangetree.org/test.htm
my code is the same except I uncommented the line right after the hdoc.write
http://www.exchangetree.org/test.asp
pulling data from http://www.exchangetree.org/test.htm
my code is the same except I uncommented the line right after the hdoc.write
I meant, this option works http:Q_28439525.html#a40083287 and so does xmlhttp post that Big Monty gave you.
I think you have an answer between all of this, it is just not the same as what you did on the other server. They probably had a component installed that you no longer have.
I think you have an answer between all of this, it is just not the same as what you did on the other server. They probably had a component installed that you no longer have.
ASKER
Yes, it is the server, not sure what. Other com objects such as fso work.
Any ideas on configs in IIS that would cause this?
Any ideas on configs in IIS that would cause this?
I don't think there's anything in IIS that would fix this, it's either a permissions issue or the DLL needs to be re-registered. Unfortunately I don't know what DLL controls that com object.
I have to jump offline for a bit, will check back in later.
good luck!
I have to jump offline for a bit, will check back in later.
good luck!
ASKER
Tried this using the msxml object for retrieving the html. Same result.
It works in vb script running locally in a .vbs file
I need the htmlfile object because of its html dom based features
Dim html, http
set html = Server.CreateObject("htmlf ile")
Set http = Server.CreateObject("MSXML 2.XMLHTTP" )
http.open "POST", Server.MapPath("test.html" ), False
http.send
response.write http.responseText
html.write http.responseText
set html = nothing
set http = nothing
It works in vb script running locally in a .vbs file
I need the htmlfile object because of its html dom based features
Dim html, http
set html = Server.CreateObject("htmlf
Set http = Server.CreateObject("MSXML
http.open "POST", Server.MapPath("test.html"
http.send
response.write http.responseText
html.write http.responseText
set html = nothing
set http = nothing
What is it you are trying to extract from this?
I have used the xmlhttp post that big monty showed you to grab a page, remove some classes and add some others based on the html pattern and scrap only the portion I needed to display on a website. This was for a team site that had permission to grab some data from a league site for standings. I know it can be done.
I have used the xmlhttp post that big monty showed you to grab a page, remove some classes and add some others based on the html pattern and scrap only the portion I needed to display on a website. This was for a team site that had permission to grab some data from a league site for standings. I know it can be done.
<!DOCTYPE html>
<html>
<head>
</script>
</head>
<body>
Test Content
</body>
</html>
This http:Q_28439525.html#a40083287 is doing I think exactly what you are trying to do here http:#a40083611
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tested on another server. It works out of the box. This is two servers now that work fine.
The issue is obviously something quirky with the virtual server.
I think my next step is to approach the hosting company, jodohost, and have them try it on another one of their servers.
I feel like I gained what I needed to solve this problem. I have enough to at least go to the hosting company.
Awarding points. I hope this is acceptable.
Thanks a bunch!
The issue is obviously something quirky with the virtual server.
I think my next step is to approach the hosting company, jodohost, and have them try it on another one of their servers.
I feel like I gained what I needed to solve this problem. I have enough to at least go to the hosting company.
Awarding points. I hope this is acceptable.
Thanks a bunch!
ASKER
Great help with a very challenging problem!
I think it is part of being a classic asp dev. I always fee like every server is completely different and only 90% of what I have on one server will work on the next. I have been making the switch to PHP. At least there it is a matter of which version is installed and based on that you know exactly what you have.
Best of luck!
Best of luck!
none of my answers helped you out at all? bummer!
figured it would have bee n a split since I confirmed that the code was correct as well on my own server, and suggested that it was a server configuration issue as well.
oh well, glad you have a game plan going forward
figured it would have bee n a split since I confirmed that the code was correct as well on my own server, and suggested that it was a server configuration issue as well.
oh well, glad you have a game plan going forward
ASKER
I should have done it that way. :-(
Also, depending on your version of iis, you'll need to change a setting in there as well to send the errors to the browser. I believe it's under the ASP section under debugging