Access to remote URLs

In this tutorial we will used Microsoft's XMLHTTP Object to request a page to a remote address from our server. This Object is included in Microsoft's  XML DOM component, which is probably installed in your server.

The traditional usage of  Microsoft's XMLHTTP Object is to access remote XML files. In this basic tutorial we will used it to obtain the text code from a remote server. It will be the same information our browser will get when visiting that page.

In the example bellow we have set up a variable named GotothisURL which contains the url of the page we will asked our server to visit. The response to this visit will be saved to variable ResponsePage.
 

GetremoteURL.asp 
<%
 ' Intruduce the url you want to visit
 GotothisURL = "http://www.codedcode.com

 ' Create the xml object
 Set GetConnection = CreateObject("Microsoft.XMLHTTP")
 ' Conect to specified URL
 GetConnection.Open "get", GotothisURL, False
 GetConnection.Send 

 ' ResponsePage is the response we will get when visiting GotothisURL
 ResponsePage = GetConnection.responseText

' We will write 
 Response.write (ResponsePage)

 Set GetConnection = Nothing
 %>

In the example avobe we may use a URL like http://www.codedcode.com?name=Joe&lastname=Zarzandi. The example above will work with get method. You may try http://www.google.asp?q=asp to search for asp in google search engine (unfortunatelly is not legal to do so without visiting their site unless we used the method shown in the script bellow).

In the example above we have request for all content of the response page, but it is possible to request only  headers (check code in bold in the script), but we may request only for specific headers. You will need to change line 12 in the script:

ResponsePage = GetConnection.getallResponseHeaders
The response page will be something similar to this:
Server: Microsoft-IIS/5.0 Date: Thu, 31 Apr 2002 14:25:20 GMT MicrosoftOfficeWebServer: 5.0_Pub Connection: keep-alive Connection:
Keep-Alive Content-Length: 11063 Content-Type: text/html Cache-control: private


We may also request for specific parts of the information included in the headers (check a regular :

To request for Server:
ResponsePage = GetConnection.getResponseHeader("Server")
To request for Date:
ResponsePage = GetConnection.getResponseHeader("Date")

To request for Content Length:
ResponsePage = GetConnection.getResponseHeader("Content-Length")

...

In the example bellow we have add some code to avoid error messages when url is not available, so that we will get a alternative text (line 17)
 
GetremoteURL.asp
<%
 ' Intruduce the url you want to visit
 GotothisURL = "http://www.codedcode.com

 ' Create the xml object
 Set GetConnection = CreateObject("Microsoft.XMLHTTP")
 ' Conect to specified URL
 GetConnection.Open "get", GotothisURL, False
 on error resume next
 GetConnection.Send 

 ' ResponsePage is the response we will get when visiting GotothisURL
 ResponsePage = GetConnection.responseText

' We will write 
if ResponsePage="" then 
Response.write("The page is not available")
else
Response.write(ResponsePage)
end if

 Set GetConnection = Nothing
 %>




Google






   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006-2010 All Rights Reserved By CodeDcode.Com : HTML : RSS : TEXT : XML