以下asp代码示例:
url="http://ip-api.com/csv/"&ip&"?lang=zh-CN&fields=message,country,regionName,city"
Function getHTTPPage(url)
url=cstr(url)
dim Http
set Http=server.createobject("MSXML2.ServerXMLHTTP")
Call Http.setTimeouts(90000,90000,90000,90000)
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
result= bytesToBSTR(Http.responseBody,"utf-8")
set http=nothing
if err.number<>0 then err.Clear
getHTTPPage = result
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