当前位置:编程学习 > asp >>

asp msxml.xmlhttp采集数据并解决乱码问题

asp教程 msxml.xmlhttp采集数据并解决乱码问题
'在asp中要采集数据一般会利用了asp xmlhttp这个组件来实例了,很多时候采集过来的中文会是乱码,我们利用

bytestobstr函数转换解决了采集乱码的问题。
function gethttppage(url)
on error resume next
dim http
set http=server.createobject("msxml2.xmlhttp")
http.open "get",url,false
http.send()
if http.readystate<>4 then
  exit function
end if
gethttppage=bytestobstr(http.responsebody,"utf-8")
set http=nothing
if err.number<>0 then
  response.write "<div align='center'><b>www.zzzyk.com 服务器获取文件内容出错</b></div>"
  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
补充:asp教程,XML相关 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,