<%
dim len,str,rn,start1,end1,end2,body
len=Request.TotalBytes
str=Request.BinaryRead(len)
Response.BinaryWrite str
Response.write "<hr>"
set asfman=Server.CreateObject("ADODB.Stream")
asfman.Type=1
asfman.Mode=3
asfman.Open
asfman.Write str
asfman.Position=0
asfman.Type=2
asfman.Charset="GB2312"
Response.write asfman.ReadText
set asfman=nothing
%>
用BinaryWrite输出BinaryRead的数据是完全正常,而用stream先存入byte然后输出text指定编码却不能正确地输出中文,与直接把byte当作text存入stream然后取出一样不能正确地输出中文,只能输出ascii字符。(所以在处理ascii字符的时候直接把byte当text存入取出即可)很是疑惑。
因为用stream对象处理xmlhttp.responseBody的byte数据输出中文是完全正常的:
Dim ADOS
Set ADOS = Server.CreateObject("Adodb.Stream")
With ADOS
.Type = 1
.Mode = 3
.Open
.Write Body 'Body为byte
.Position = 0
.Type = 2
.Charset = Cset
SenFe_BytesToBstr = .ReadText
.Close
End With
Set ADOS = Nothing
function getExt(bstr)
{
var stm = Server.CreateObject("ADODB.Stream");
stm.Type = 2;
stm.Mode = 3;
stm.Open();
stm.WriteText(bstr);
stm.Position = 0;
stm.CharSet = "GB2312";
var fmText = stm.ReadText();
stm.Close();
stm = null;
return /filename=\".+(\..+)\"/.exec(fmText)[1];
}
发现用binarywrite完全可以处理xmlhttp.responseBody数据,所以用asp的话,可以不通过stream来处理它,而直接bianrywrite输出即可:
<%
Function GetData(GetUrl)
Dim Http
Set Http = Server.CreateObject("Msxml2.ServerXMLHTTP")
With Http
.Open "GET",GetUrl,False
.SetRequestHeader "Referer",GetUrl
.Send
GetData=http.responseBody
End With
Set Http = Nothing
End Function
function streamobj(str)
set asfman=Server.CreateObject("ADODB.Stream")
asfman.Type=1
asfman.Mode=3
asfman.Open
asfman.Write str
asfman.Position=0
asfman.Type=2
asfman.Charset="gb2312"
streamobj=asfman.ReadText
set asfman=nothing
end function
Response.write streamobj(GetData("
http://www.baidu.com"))
%>
<%
Function GetData(GetUrl)
Dim Http
Set Http = Server.CreateObject("Msxml2.ServerXMLHTTP")
With Http
.Open "GET",GetUrl,False
.SetRequestHeader "Referer",GetUrl
.Send
GetData=http.responseBody
End With
Set Http = Nothing
End Function
Response.BinaryWrite GetData("
http://www.baidu.com")
%>
posted on 2006-11-23 11:08
汪杰 阅读(1424)
评论(1) 编辑 收藏 引用 所属分类:
asp(javascrpt)