ASP动态页面生成HTML静态页面-编码UTF-8

ASP 1452 0 2013-02-16

ASP动态页面生成HTML静态页面-编码UTF-8
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Option Explicit
Session.CodePage=65001
Response.Charset = "utf-8"

Dim Url,Html,HtmlPath

Select Case request("update")
Case "default"
Url      ="http://it.hilo8.com"
HtmlPath = "/it.html"
Case else
Response.Write UCase("ERROR : UPDATE FAILED!<br />Time:"&now())
Response.End()
End Select

Html = getHTTPPage(Url)
'Response.write Html
call createHtmlFile(Html,HtmlPath)
response.Write UCase("update done successfully!<br />Time:"&now())

'======================================================================

function getHTTPPage(url)
    dim Http
    set Http=server.createobject("MSXml2.XmlHTTP")
    Http.open "GET",url,false
    Http.send()
    if Http.readystate<>4 then
    exit function
    else    
       If Http.status=200 Then
           'response.write replace(BytesToBstr(http.responseBody,"utf-8"),chr(10),"")
       End If
    end if
    getHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")
    set http=nothing
    if err.number<>0 then err.Clear
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

function createHtmlFile(str,filename)
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Open
.Charset = "utf-8"
.Position = objStream.Size
.WriteText=str
.SaveToFile server.mappath(filename),2
.Close
End With
Set objStream = Nothing
end function
%>

上一篇:asp之转换函数示例

下一篇:asp中网页源代码的获取,跨域的实现及js的传值

讨论数量:0

请先登录再发表讨论。 2024-05-06

天涯网魂
3 杠 5 星
TA 的文章
TA 的随言
TA 的资源链