管理杂谈OA答疑ERP答疑教程搜索

asp中如何通过ajax获取远端服务器上指定页面的数据


:asp中如何通过ajax获取远端服务器上指定页面的数据


下面以asp从ip138网站中获取IP地址为例说明:

Function getAddr(from_IP)

getAddr="未知地址"

if from_IP &"CS"<>"CS" then

dim objXML,getAddrTmp

set objXML=createobject("MSXML2.XMLHTTP")

objXML.open "post","https://www.ip138.com/iplookup.asp?action=2&ip="& from_IP,false

objXML.send()

If objXML.readystate<>4 then

exit function

End If

getAddrTmp=BytesToBstr(objXML.responseBody)

if instr(getAddrTmp,"本站数据:")>0 and instr(getAddrTmp,"</li>")>0 then getAddr=left(split(split(getAddrTmp,"本站数据:")(1),"</li>")(0),50)

set objXML=nothing

if err.number<>0 then err.Clear

end if

End Function


Function BytesToBstr(body)

dim objstream

set objstream = CreateObject("adodb.stream")

objstream.Type = 1

objstream.Mode =3

objstream.Open

objstream.Write body

objstream.Position = 0

objstream.Type = 2

objstream.Charset = "GB2312"  '编码方式 

BytesToBstr = objstream.ReadText

objstream.Close

set objstream = nothing

end Function


temp_ip="156.2.36.96"

response.write (getAddr(temp_ip))


更多精彩文章浏览...
点击右上角图标分享到朋友圈
官方网站:http://www.clicksun.cn
咨询热线:400-186-1886
服务邮箱:service@clicksun.cn