URL Property  

Gets and sets the current URL used to access a resource on the server.


object.URL [= url ]


The URL property returns the current Uniform Resource Locator string which is used by the control to access a resource on the server. URLs have a specific format which provides information about the server, port, resource, as well as optional information such as a username and password for authentication:

http://[username : [password] @] hostname [:port] / resource [? parameters]

The first part of the URL is the protocol and in this case will always be "http", or "https" if a secure connection is being used. If a username and password is required for authentication, then this will be included in the URL before the name of the server. Next, there is the name of the server to connect to, optionally followed by a port number. If no port number is given, then the default port for the protocol will be used. This is followed by the resource, which is usually a path to a file or script on the server. Parameters to the resource may also be specified, which are typically used as arguments to a script that is executed on the server.

Here are some common examples of URLs used to access resources on an HTTP server:

In this example, the server is www.example.com and the resource is /products/index.html. The default port will be used to access the resource, and no username and password is provided for authentication.

In this example, the server is www.example.com and the resource is /products/index.html. However, the client should connect to an alternative port number, in this case 8080.

In this example, the server is www.example.com and the resource is the script /order/confirm.asp. Because the protocol is https, a secure connection on port 443 will be established.

In this example, the server is www.example.com and the resource is /~jsmith/personal/index.html. The port 8080 will be used to access the resource, and access to the resource will be authenticated with the username "jsmith" and the password "secret".

When setting the URL property, the control will parse the string and automatically update the HostName, RemotePort, UserName, Password and Resource properties according to the values specified in the URL. This enables an application to simply provide the URL and then call the Connect method to establish the connection.

Note that if this property is assigned a value which cannot be parsed, the control will throw an error that indicates that the property value is invalid. In a language like Visual Basic it is important that you implement an error handler, particularly if you are assigning a value to the property based on user input. If the user enters an invalid URL and there is no error handler, it could result in an exception which terminates the application.

Data Type



' Setup error handling since the control will throw an error
' if an invalid URL is specified

On Error Resume Next: Err.Clear
HttpClient1.URL = Text1.Text

' Check the Err object to see if an error has occurred, and
' if so, let the user know that the URL is invalid

If Err.Number <> 0 Then
    MsgBox "The specified URL is invalid", vbExclamation
    Exit Sub
End If

' Reset error handling and connect to the server using the
' default property values that were updated when the URL
' property was set (ie: HostName, RemotePort, Resource, etc.)

On Error GoTo 0
nError = HttpClient1.Connect()

If nError > 0 Then
    MsgBox HttpClient1.LastErrorString, vbExclamation
    Exit Sub
End If

' Get the resource and store the data in a string buffer
nError = HttpClient1.GetData(HttpClient1.Resource, strBuffer)

See Also

HostAddress Property, HostName Property, Password Property, RemotePort Property, Resource Property, UserName Property, Connect Method