当前位置:八联网络科技帮助中心 > 软件常见问题 > 操作软件
帮助流程
如果在使用我们的产品中遇到问题,建议您在“常见问题”中查询解决方法;
如果没有找到该问题的解决方法,您可以在“问题搜索”中进行搜索;
如果搜索后没有找到满意答案,您可以“在线客服”,我们会尽快给您答复。
将asp页面转换成htm页面,减少资源的消耗
作者:客服中心 文章来源:八联网络科技 更新时间:2015-06-29

前段时间有个asp页面执行起来很慢,访问人数又颇多,而且又不经常修改,又懒得直接做成静态的,每次都要从服务器下载来改,只好想办法把asp页面转化成htm静态页面了,以增加承载的访问人数和较少资源的消耗。此代码适合独立主机。 
  <%
  Function GetPage(url)  ’
获得文件内容
   dim Retrieval
   Set Retrieval = CreateObject("Microsoft.XMLHTTP")
   With Retrieval
   .Open "Get", url, False ’, "", ""
   .Send
   GetPage = BytesToBstr(.ResponseBody)
   End With
   Set Retrieval = Nothing
  End Function
  
  Function BytesToBstr(body)
   dim objstream
   set objstream = Server.CreateObject("adodb.stream")
   objstream.Type = 1
   objstream.Mode =3
   objstream.Open
   objstream.Write body
   objstream.Position = 0
   objstream.Type = 2
   objstream.Charset = "GB2312"
   BytesToBstr = objstream.ReadText
   objstream.Close
   set objstream = nothing
  End Function
  
  on error resume next
  Url="
http://www.sina.com.cn"’要读取的页面地址
  response.write "
开始更新首页..."
  wstr = GetPage(Url)
  
  ’response.write(wstr)
  Set fs=Server.CreateObject("Scripting.FileSystemObject")
  
  ’if not MyFile.FolderExists(server.MapPath("/html/")) then
  ’MyFile.CreateFolder(server.MapPath("/html/"))’
  ’end if
  
  ’
要存放的页面地址
  dizhi=server.MapPath("index.htm")
  If (fs.FileExists(dizhi)) Then
  fs.DeleteFile(dizhi)
  End If
  
  Set CrFi=fs.CreateTextFile(dizhi)
  Crfi.Writeline(wstr)
  set CrFi=nothing
  set fs=nothing
  response.write "...<font color=red>
更新完成!</font>"
  %>      
 
代码算是最简单的,直接保存成一个asp文件即可,只要把URL(要转化的asp地址)和地址(要保存的html地址)设置好就可以了,一般这两个文件在同一个目录,才能保证图片或者cssjs起作用。