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
投稿

猜你喜欢

  • 超常用的PHP正则表达式收集整理

    2024-05-03 15:35:57
  • Django零基础入门之运行Django版的hello world

    2022-11-10 02:44:58
  • Windows安装Anaconda并且配置国内镜像的详细教程

    2023-07-06 13:45:15
  • Python使用xlrd和xlwt实现自动化操作Excel

    2021-08-24 10:54:19
  • 如何远程连接SQL Server数据库图文教程

    2024-01-21 16:23:30
  • 再谈Python中的字符串与字符编码(推荐)

    2023-06-15 23:25:08
  • python交易记录整合交易类详解

    2022-09-15 20:18:37
  • SQL Server数据库定时自动备份

    2024-01-13 22:01:25
  • Python中的类与类型示例详解

    2023-08-12 12:21:42
  • jQuery 1.4新特性及其变化(上)

    2010-01-18 16:33:00
  • 图片预载ImageLoader 1.1 Release

    2008-11-04 20:04:00
  • mysql数据库乱码之保存越南文乱码解决方法

    2024-01-14 12:12:24
  • 在Python中编写数据库模块的教程

    2024-01-22 21:28:40
  • python把ipynb文件转换成pdf文件过程详解

    2022-07-27 23:50:24
  • js动态显示当前日期,时间和星期代码

    2007-08-14 12:31:00
  • 网页布局设计基础

    2008-10-16 13:58:00
  • Vue 3.x+axios跨域方案的踩坑指南

    2024-05-09 09:21:15
  • 如何用Python来搭建一个简单的推荐系统

    2022-07-20 22:17:33
  • 微信小程序实现单个卡片左滑显示按钮并防止上下滑动干扰功能

    2024-04-18 10:03:54
  • Git配置别名简化操作命令方式详解

    2022-03-20 03:34:12
  • asp之家 网络编程 m.aspxhome.com