欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp base64 utf-8为了兼容asp.net的base64

程序员文章站 2022-05-08 13:06:41
复制代码 代码如下:<%@language="vbscript" codepage="65001"%> <%session.codepage=65001%...
复制代码 代码如下:

<%@language="vbscript" codepage="65001"%>
<%session.codepage=65001%>
<!--#include file="base64.asp"-->
<%
function aspurldecode(strvalue)
dim varary, varelement, objstream, lngloop, flag
strvalue = replace(strvalue, "+", " ")
varary = split(strvalue, "%")
flag = varary(0) = ""
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.mode = 3
.open
for each varelement in varary
if varelement <> empty then
if len(varelement) >= 2 and flag then
.writetext chrb(cint("&h" & left(varelement, 2)))
for lngloop = 3 to len(varelement)
.writetext chrb(asc(mid(varelement, lngloop, 1)))
next
else
for lngloop = 1 to len(varelement)
.writetext chrb(asc(mid(varelement, lngloop, 1)))
next
flag = true
end if
end if
next
.writetext chr(0)
.position = 0
aspurldecode = replace(convunicode(.readtext), chr(0), "", 1, -1, 0)
on error resume next
.close
set objstream = nothing
end with
end function



function convunicode(byval strdata)
dim rs, stm, bytary, intlen
if len(strdata & "") > 0 then
strdata = midb(strdata, 1)
intlen = lenb(strdata)
set rs = server.createobject("adodb.recordset")
set stm = server.createobject("adodb.stream")
with rs
.fields.append "x", 205, intlen
.open
.addnew
rs(0).appendchunk strdata & chrb(0)
.update
bytary = rs(0).getchunk(intlen)
end with
with stm
.type = 1
.open
.write bytary
.position = 0
.type = 2
.charset = "utf-8"
convunicode = .readtext
end with
end if
on error resume next
stm.close
set stm = nothing
rs.close
set rs = nothing
end function


%>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<%


'base64编码后,比起.net多了77u/
response.write("base64编码后:"&base64encode("阿会楠")&"<br />")

'base64解码后
response.write("base64解码后:"&base64uncode("6zi/5lya5qwg")&"<br />")

%>
</body>
</html>