ASP获取网页内容(解决乱码问题)

来源:风之相随blog 时间:2009-07-26 10:44:00 

ASP使用xmlhttp获取远程网页内容,解决乱码问题

方法一:

<%
function getHTTPPage(url)
on error resume next
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
  exit function
end if
getHTTPPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end function
Function bytes2BSTR(vIn)
dim strReturn
dim i1,ThisCharCode,NextCharCode
strReturn = ""
For i1 = 1 To LenB(vIn)
  ThisCharCode = AscB(MidB(vIn,i1,1))
  If ThisCharCode < &H80 Then
   strReturn = strReturn & Chr(ThisCharCode)
  Else
   NextCharCode = AscB(MidB(vIn,i1+1,1))
   strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
   i1 = i1 + 1
  End If
Next
bytes2BSTR = strReturn
End Function
Response.Write(getHTTPPage(http://www.cidianwang.com))
%>

方法二:

 

<%
On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
Function GetBody(url)
on error resume next
Set Retri = CreateObject("Microsoft.XMLHTTP")
With Retri
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retri = Nothing
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
Response.Write(getHTTPPage(http://www.cidianwang.com))
%>

标签:ajax,乱码,asp
0
投稿

猜你喜欢

  • js增强的自定义事件模型

    2008-02-18 12:37:00
  • 你的网页“面目全非”过吗?

    2010-07-02 16:24:00
  • JS载入数据效果!loading

    2009-01-20 18:35:00
  • 非常详细的IFRAME的属性参考手册

    2008-02-12 12:45:00
  • ASP 相关文章或者相关产品

    2011-03-30 11:12:00
  • oracle 服务启动,关闭脚本(windows系统下)

    2009-07-26 08:57:00
  • css学习笔记:div在IE6下无法遮盖select

    2009-04-30 13:21:00
  • CSS灵活运行注释带来的益处

    2008-04-21 13:51:00
  • 网页设计中怎么将px换成em

    2008-04-16 13:50:00
  • HTML,CSS和JavaScript速查表

    2010-09-16 13:02:00
  • 浅谈LogMiner的使用方法

    2009-02-28 11:12:00
  • CSS滤镜示范(filter)附源代码(静态滤镜)

    2008-05-18 12:42:00
  • asp 多关键词搜索的简单实现方法

    2011-04-11 10:45:00
  • 良好体验,必须是全方位的

    2009-09-24 13:32:00
  • sqlserver 索引的一些总结

    2012-08-21 11:03:31
  • 常用的匹配正则表达式和实例

    2008-06-07 09:19:00
  • 关于字体的一些思考

    2008-03-03 12:53:00
  • web脚本程序攻击的防范

    2007-10-18 13:29:00
  • SQL SERVER 2005中的同步复制技术

    2009-01-05 13:44:00
  • Windows mysql命令行导入 .sql文件

    2010-12-03 16:12:00
  • asp之家 网络编程 m.aspxhome.com