关于asp生成静态网页(XMLHTTP)?
我用XMLHTTP生成静态网页,可是提示错误:
错误类型:
(0x80004005)
未指定的错误
/glp/AddMenu.asp, 第 11 行
<%
function SaveFile(LocalFileName,RemoteFileUrl)
Dim Ads, Retrieval, GetRemoteData
' On Error Resume Next
Set Retrieval = Server.CreateObject( "Microsoft.XMLHTTP ")
With Retrieval
.Open "Get ", RemoteFileUrl, False '提示这行出错,不知怎回事
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject( "Adodb.Stream ")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(LocalFileName), 2
.Cancel()
.Close()
End With
Set Ads=nothing
if err <> 0 then
SaveFile = false
err.clear
else
SaveFile = true
end if
End function
%>
<%
Dim ID,ParentID,text,htext,URL,str
Dim Cmd1,rs1,Data
%>
<%
set Cmd1=Server.CreateObject( "ADODB.Command ")
Cmd1.ActiveConnection = MM_myconn_STRING
ParentID=Trim(Request.Form( "ParentID "))
text=Trim(Request.Form( "nodetext "))
htext=Trim(Request.Form( "htext "))
URL=Trim(Request.Form( "NodeURL "))
Data=Trim(Request.Form( "data "))
Response.Write(Data)
str= "Insert into treeview(parentID,nodetext,hint,url,data,target) values ( "&ParentID& ", ' "&text& " ', ' "&htext& " ', ' "&URL& " ', 'Description= "&Data& " ', ' "& "right ') "
Cmd1.CommandText=str
Cmd1.Execute
Cmd1.ActiveConnection.Close
Response.Write( "正在生成静态网页... "& " <br> ")
if SaveFile( "1.htm ", "main.asp ") then
Response.write "已生成 "& " <br> "
else
Response.write "没有生成 "& " <br> "
end if
'Response.Redirect( "MangmentTreeView.asp ")
%>
------解决方案--------------------如上。。。服务器端请求必须是完整虚拟路径。。
http://www.xxxx.com/main.asp
http://localhost/main.asp
这类的。。
------解决方案--------------------...
我还刻意说了下。要完整虚拟路径。。
不是绝对路径。。
这个正则有点老了。。不过可以实现。。
<%
Function getURL(f_url)
'获取目标文件绝对路径
Dim r, url
Set r = new RegExp '创建正则对象
r.Pattern = "\/[^\.\/]+\.[A-Za-z]+ " '匹配/*.*文件
'获取http://域名/目前文件地址
url = "http:// " & Request.ServerVariables( "HTTP_HOST ") & Request.ServerVariables( "URL ")
getURL = r.Replace(url, " ") & "/ " & f_url '把匹配字符串替换成空,并且加入/目标文件,并且返回结果
Set r = Nothing
End Function
getURL( "main.asp ")
%>