Question:
CopyCode The Code is as follows: <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>
How can I use ASP to store and read data from the above.
Answer:Copy codeThe Code is as follows: <%
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
'Function name: bytestobstr
'Function: Convert binary data into characters
'Parameter: Body-binary data, cset-text encoding method
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 "your IP address is (ASP obtains the real IP address):" & Split (tempstr, ") (1)" "& Split (tempstr ,"""") (5) "" & replace (split (tempstr, ") (7)," city "," ")
%>