Example Code:
Example 1 :: to run a site HTTP
<%
Set HttpObj = Server.CreateObject("AspHTTP.Conn")
HTTPObj.Url = "http://www.-----.com"
HTTPObj.TimeOut = 5 'set the timeout
strResult = HTTPObj.GetURL
SET HTTPobj = nothing
response.write strResult
%>
Example 2 :: to get the HTML code show
<%
Set HttpObj = Server.CreateObject("AspHTTP.Conn")
HTTPObj.Url = "http://www.-----.net"
HTTPObj.TimeOut = 5 'set the timeout
strResult = HTTPObj.GetURL
SET HTTPobj = nothing
HTMLstrResult=Server.htmlEncode(strResult)
response.write HTMLstrResult
%>
Example3 and Example4 ------ off html code ----
<%
Set HttpObj = Server.CreateObject("AspHTTP.Conn")
HTTPObj.Url = "http://www.-----.net"
HTTPObj.TimeOut = 5 'set the timeout
strResult = HTTPObj.GetURL
SET HTTPobj = nothing
HTMLstrResult=Server.htmlEncode(strResult)
'response.write HTMLstrResult
'-----function clearHTMLCode(originCode)----
function clearHTMLCode(originCode)
dim reg
set reg = new RegExp
reg.Pattern = "<[^>]*>"
reg.Global = true
clearHTMLCode = reg.Replace(originCode, "")
end function
'-----function Checkin(s)----------
function Checkin(s)
s=trim(s)
s=replace(s,vbCrlf,"")
s=replace(s,chr(9),"")
s=replace(s," ","")
s=replace(s," ","")
Checkin=s
end function
' chr(10) may change some code
'----Example 3------
response.write clearHTMLCode(strResult)&"<hr>"
'----Example 4------
response.write Checkin(clearHTMLCode(strResult))
%>
------ Example 5 list all hrefs: HttpObj.GetHREFs-----
<html>
<body>
<% '---------------HttpObj.GetHREFs--------
Server.ScriptTimeout = 5
Set HttpObj = Server.CreateObject("AspHTTP.Conn")
HttpObj.Url = "http://----.com/"
HttpObj.RequestMethod = "GET"
HttpObj.UserAgent = "Mozilla/2.0 (compatible; MSIE 6.0B; Windows NT)"
strResult = HttpObj.GetURL
Response.Write "<h2>A HREF List</h2>"
varHREFArray = HttpObj.GetHREFs
intHREFArrayLimit = UBound(varHREFArray) -1
For I = 0 to intHREFArrayLimit
Response.Write I+1&" : "&varHREFArray(I) & "<br>" & VBCrLF
Next
%>
</body>
</html>
-----Example 6 ::------------
<%
' get image/gif
Response.ContentType = "image/gif"
Set HTTPObj = Server.CreateObject("AspHTTP.Conn")
HTTPObj.Url = "http://----.com/---.gif"
HTTPObj.GetURL
Response.BinaryWrite HTTPObj.BinaryData
%>
------- Example 7 get and save image file
<%
Server.ScriptTimeout = 240
Set HttpObj = Server.CreateObject("AspHTTP.Conn")
HttpObj.Url = "http://www.----.com/---.gif"
HttpObj.FollowRedirects = false
HttpObj.RequestMethod = "GET"
HttpObj.UserAgent = "Mozilla/2.0 (compatible; MSIE 6.01; Windows NT)"
HttpObj.SaveFileTo = "D:/myPath/log.gif"
HttpObj.GetURL
Response.Write "image saved"
%>
<% ' ---- Example 8 ----get file and save
Set HttpObj = Server.CreateObject("AspHTTP.Conn")
HTTPObj.Url = "http://www.----.com/"
'HTTPObj.PostData = "suid=jimb&pwd=macabre&id=32&val=1.5"
HTTPObj.TimeOut = 1800
HTTPObj.Accept = "*/*"
HTTPObj.FollowRedirects = true
HTTPObj.Port = 80
'HTTPObj.Proxy = "---.net:8080"
'HTTPObj.ProxyPassword = "proxyusername:proxypassword"
HttpObj.SaveFileTo = "D:/myPath/newfilename.html"
HTTPObj.UserAgent = "Mozilla Compatible (MS IE 3.01 WinNT)"
HTTPObj.Protocol = "HTTP/1.1"
HTTPObj.Authorization = "USER:pass"
HTTPObj.ContentType = "application/x-www-form-urlencoded"
HTTPObj.RequestMethod = "POST"
'HTTPObj.GetHREFs
'HTTPObj.RequestMethod = "HEAD"
strResult = HTTPObj.GetURL
response.write strResult
%>
---------- Ezer Tips ----------
反制他人不經瀏覽器或經快捷徑工具列
來獲取網頁資料……
SEs 也已經在2006漸漸開始注意到
並發展….. 反制功能
其實獲取網頁資料就好比網界文機器人
獲取網頁資料…
Ezer Tips:反制功能其實也不難
小心使用JAVA可能會影響HttpObj.GetHREFs
的計算結果
-------------- |