ASP 取得騰訊IP位址的程式碼用ASP來存儲,從上面讀取出來的資料。提問:
複製代碼代碼如下:
<script type=text/javascript src=http://fw.qq.com/ipaddress></script>
<script type=text/javascript>
var hehe1=IPData[2]
var hehe2=IPData[3]
alert(hehe1);
alert(hehe2);
document.write(IPData.join(' '));
</script>
如何用ASP來存儲,從上面讀取出來的資料呢。
答:
複製代碼代碼如下:
<%
function GetResStr(URL,code)
err.clear
dim Http,ReturnStr
Set Http=server.createobject(Microsoft.XMLHTTP)
Http.open GET,URL,False
Http.Send()
If Http.Readystate =4 Then
If Http.status=200 Then
ReturnStr=BytesToBstr(http.responseBody,code)
GetResStr=ReturnStr
End If
End If
End Function
'函數名稱:BytesToBstr
'作用:轉換二進位資料為字符
'參數:Body-二進位資料,Cset-文字編碼方式
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
dim vUrl,TempStr
vUrl=http://fw.qq.com/ipaddress
TempStr=GetResStr(vUrl,gb2312)
response.write 您的IP為(asp取得真實IP):&split(TempStr,)(1) &split(TempStr,)(5) &replace(split(TempStr,)(7),市,)
%>