通过XMLHTTP实现首页生成,大家分享一下,可提出修改建议!
调用:GreateHttpFile 动态页面地址,要保存的路径及文件名
代码:
Sub GreateHttpFile(Url,FilePath)
Dim MyFile,HtmlContent
On Error Resume Next
If Url = "" Or FilePath = "" Then
ErrMsg "<li>Url参数或FilePath参数为空,请与管理员联系!"
Response.End
End If
HtmlContent = GetHttpPage(Url)
Set MyFile=Server.CreateObject("Scripting.FileSystemObject")
Set CrFi=MyFile.CreateTextFile(Server.MapPath(""&Filepath&""),true)
CrFi.Writeline(""&HtmlContent&"")
CrFi.close
If Err.Number = 0 then
Err.Clear
Response.write "<script>alert('操作成功!');history.back();</script>"
Response.End
Else
Err.Clear
Response.write "<script>alert('操作失败,网页地址可能出错,请与管理员联系!');history.back();</script>"
Response.End
End If
End Sub
Function GetHttpPage(url)
Dim Http
Set Http=server.createobject("MSXML2.XMLHTTP")
'Set Http=server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
'Http.open "POST",url,false
Http.send()
If Http.readystate<>4 then
exit Function
End If
GetHttpPage = BytesToBstr(Http.responseBody,"GB2312")
'GetHttpPage = bytesToBSTR(Http.responseBody,"Shift-JIS")
Set Http=Nothing
If Err.Number<>0 then
Err.Clear
End If
End Function
Function BytesToBstr(Body,Cset)
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 = Cset
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
End Function