Access to remote URLs
Examples based in this tutorial:
    Check domain name availability
Get keywords from remote url
Google search in your site

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.asptutorial.info

 ' 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.asptutorial.info?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.asptutorial.info

 ' 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
 %>


AspTutorial.info.