asp获取网页

2018 年 4 月 1 日2010

asp获取网页

Function getHTTPPage(url)

'创建对象

dim objXML
set objXML=server.createobject("MSXML2.serverXMLHTTP")
objXml.SetTimeOuts 20000, 20000, 30000, 30000

'发送请求,网址为url,包含http://

objXML.open "GET",url,false'
objXML.send()
If objXML.readystate<>4 then
getHTTPPage=""
exit function
End If

'处理返回的结果

if objXML.responseText<>"" then

getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
else
getHTTPPage=""
end if

set objXML=nothing
if err.number<>0 then err.Clear
End Function

'转换编码的函数

Function BytesToBstr(ubody,cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write ubody
objstream.Position = 0
objstream.Type = 2
objstream.Charset = cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function

0 0