簡單實例: 使用這個組件十分簡單 1.創(chuàng)建對象 2.設定一些屬性 3.調(diào)用GetUrl方法
下面是vbscript使用AspHTTP的示例代碼
Set HttpObj = Server.CreateObject("AspHTTP.Conn") HttpObj.Url = "http://www.myfinancialpage.com/qrtresults.html" strResult = HttpObj.GetURL 變量strResult現(xiàn)在包含一個字符串從http://www.myfinancialpage.com/qrtresults.html GET獲得的文檔結果
實例:獲得GIF文件 <% rem This demo pulls a GIF image from www.microsoft.com Server.ScriptTimeout = 240 Set HttpObj = Server.CreateObject("AspHTTP.Conn") HttpObj.Url = "http://www.microsoft.com/library/images/gifs/toolbar/write.gif" HttpObj.FollowRedirects = false HttpObj.RequestMethod = "GET" HttpObj.UserAgent = "Mozilla/2.0 (compatible; MSIE 3.0B; Windows NT)" HttpObj.SaveFileTo = "c:\write.gif" HttpObj.GetURL Response.Write "<hr><h3>Headers Received</h3><pre>" & HttpObj.Headers & "</pre>" %>
實例:處理和顯示URL包含的HREF <html> <body> <% Server.ScriptTimeout = 240 Set HttpObj = Server.CreateObject("AspHTTP.Conn") HttpObj.Url = "http://www.genusa.com/asp/tools.html" HttpObj.RequestMethod = "GET" HttpObj.UserAgent = "Mozilla/2.0 (compatible; MSIE 3.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 varHREFArray(I) & "<br>" & VBCrLF Next %> </body> </html> (出處:熱點網(wǎng)絡)
|