asp获取最高版本的XMLHTTP组件,用于远程文件的获取,加强程序兼容性

[ 2015-12-16 15:35:14 | 作者: admin ]
字号: | |


'*********************************************************
'获取远程文件内容
'Dim Url,Html
'Url="http://www.im286.com"
'Html = getHTTPPage(Url)
'*********************************************************
function getHTTPPage(url)
On Error Resume Next
dim Http
'set Http=server.createobject("MSXML2.XMLHTTP")


'循环获取最高支持的XML组件
oxml=array("Msxml2.ServerXMLHTTP.6.0","Msxml2.ServerXMLHTTP.5.0","Msxml2.ServerXMLHTTP.4.0","Msxml2.ServerXMLHTTP.3.0","Msxml2.ServerXMLHTTP","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP")
for i=0 to ubound(oxml)
  Set HTTP = Server.CreateObject(oxml(i))
  If Err Then
    Err.Clear
    'Response.Write oxml(i)&"不支持<br/>"
  else
    Exit For
    'Response.Write oxml(i)&" 支持<br/>"
  end if
next



Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
             exit function
end if
getHTTPPage=BytesToBstrHttp(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function

Function BytesToBstrHttp(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
             BytesToBstrHttp = objstream.ReadText
             objstream.Close
             set objstream = nothing
End Function

[最后修改由 admin, 于 2015-12-16 15:38:29]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=2307

这篇日志没有评论。

此日志不可发表评论。