xmlhttp 中一个编码转换的问题

lovebanyi 2005-02-01 03:24:02
我有三个文件。
分别是xmlhttp.asp qq.asp qq.aspx(详细请看下面)
现在的问题。我用xmlhttp.asp获取qq.asp的时候不会出错。
获取qq.aspx的时候会出错。Ascb这个函数会出错 一开始我还以为是可以行得通的。后来我知道asp和asp.net的两个输出是不一样的。
我用vs.net 分别调试获取qq.asp 和获取qq.aspx的值
得到下面的情况
asp的时候 xml.ResponseBody是一个如下的数组
206 210  202 199   203 173   (估计是两个表示一个汉字)
aspx的时候得到的是  230 136 145 230 152 175 232 176 129 (估计三个表示一个汉字)
我们在直接看网页的时候。右键看到的编码asp 是 GB3213 aspx 是 UTF-8
那么下面的哪个函数 bytes2BSTR 对asp的编码显然是正确的。 现在需要帮忙的是写一个转aspx
 或者给一下。xmlhttp较全的资料 GB3213 UTF-8 编码的资料
xmlhttp
的内容是
<script language="VBscript">
dim xml
dim data
set xml=CreateObject("Msxml2.XMLHTTP")
data=""
xml.open "post","http://binbin/net2/qq.asp",false
xml.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
xml.setRequestHeader "Content-Length",len(data)

xml.send(data)
kk=xml.responseText 'responseText  responseBody
document.Write(bytes2BSTR(kk))

function bytes2BSTR(vIn)
dim strReturn,i,ThisCharCode,innerCode,Hight8,Low8,NextCharCode
strReturn=""
for i=1 to LenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
if ThisCharCode<&H80 Then
strReturn=strReturn & Chr(ThisCharCode)
else
NextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(NextCharCode))
i=i+1
end if
next
bytes2BSTR=strReturn
end function
</script>
qq.asp

<%
Response.write("我是谁")
%>

qq.aspx
<script language="C#" runat="server">
void Page_load()
{
Response.Write("我是谁");
}
</script>
...全文
134 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
poron9 2005-02-01
  • 打赏
  • 举报
回复
//UTF8转GB2312
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if len(UTFStr) >= Dig+8 then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
next
UTF2GB=GBStr
end function

function ConvChinese(x)
A=split(mid(x,2),"%")
i=0
j=0

for i=0 to ubound(A)
A(i)=c16to2(A(i))
next

for i=0 to ubound(A)-1
DigS=instr(A(i),"0")
Unicode=""
for j=1 to DigS-1
if j=1 then
A(i)=right(A(i),len(A(i))-DigS)
Unicode=Unicode & A(i)
else
i=i+1
A(i)=right(A(i),len(A(i))-2)
Unicode=Unicode & A(i)
end if
next

if len(c2to16(Unicode))=4 then
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
else
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
end if
next
end function

function c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
next
end function

function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end function

function c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
tempstr="0" & tempstr
loop
c16to2=c16to2 & tempstr
next
end function

function c10to2(x)
mysign=sgn(x)
x=abs(x)
DigS=1
do
if x<2^DigS then
exit do
else
DigS=DigS+1
end if
loop
tempnum=x

i=0
for i=DigS to 1 step-1
if tempnum>=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 & "1"
else
c10to2=c10to2 & "0"
end if
next
if mysign=-1 then c10to2="-" & c10to2
end function

//GB2313转UTF8
Function toUTF8(szInput)
Dim wch, uch, szRet
Dim x
Dim nAsc, nAsc2, nAsc3

If szInput = "" Then
toUTF8 = szInput
Exit Function
End If
For x = 1 To Len(szInput)
wch = Mid(szInput, x, 1)
nAsc = AscW(wch)
If nAsc < 0 Then nAsc = nAsc + 65536

If (nAsc And &HFF80) = 0 Then
szRet = szRet & wch
Else
If (nAsc And &HF000) = 0 Then
uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
szRet = szRet & uch
Else
uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _
Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _
Hex(nAsc And &H3F Or &H80)
szRet = szRet & uch
End If
End If
Next

toUTF8 = szRet
End Function
lovebanyi 2005-02-01
  • 打赏
  • 举报
回复
我再加了个“我”字。很明显可以看到 230 136 145 230 152 175 232 176 129 230 136 145
我字应该就是 230 136 145 ()这个意思都应该是10进制的数字
hackate 2005-02-01
  • 打赏
  • 举报
回复
我晕,不会,帮你顶。。!

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧