Class

WebRequest


Description

The WebRequest object represents an HTTP request.

Properties

Name

Type

Read-Only

Shared

Body

String

Method

String

MIMEType

String

Path

String

QueryString

String

RemoteAddress

String

Secure

Boolean

Methods

Name

Parameters

Returns

Shared

Cookie

name As String

String

Header

name As String

String

HeaderNames

String()

Parameter

name As String

String

Reset

Property descriptions


WebRequest.Body

Body As String

The data sent with the request when it's too large to be a parameter such as a file or or large amount of data.

This property is read-only.


WebRequest.Method

Method As String

Returns the request type, such as GET, POST, or PUT.

This property is read-only.


WebRequest.MIMEType

MIMEType As String

Gets or sets the HTTP "Content-Type" header. This is merely a convenience feature, setting the header manually using Header will perform the exact same task. This value defaults to "text/html".

This property is read-only.


WebRequest.Path

Path As String

Returns the part of the requested url after the path, without the query string. Using the URL http://mydomain.com/folder/file?query as an example, this property would be set to "folder/file".

This property is read-only.

In the WebApplication.HandleURL event handler, you can check the URL that was used so that you can perform different actions:

Select Case Request.Path
Case "users"
  ' Return XML containing currently logged in users back to the client
Case "status"
  ' Return XML containing status information back to the client
End Select

WebRequest.QueryString

QueryString As String

Returns the query part of the requested url. Using the URL http://mydomain.com/folder/file?query as an example, this property would be set to "query".

This property is read-only.

This code in WebApplication.HandleURL could fetch information about a user in the database and return it as XML:

Select Case Request.Path
Case "user"
  Var id As String = Request.QueryString
  If Not id.IsEmpty Then
    ' Create XML containing data for the user ID
    Var xml As String
    xml = CreateUserXML(id)

    Request.Print(xml)
    Return True
  End If
End Select

WebRequest.RemoteAddress

RemoteAddress As String

Returns the IP Address of the browser making the request.

This property is read-only.

To implement a white list for web requests to your app, you can check the remote address in WebApplication.HandleURL and ignore any that you don't approve:

If Request.RemoteAddress = "192.45.34.22" Then
  ' Do processing

  Return True
Else
  Return False ' Don't handle the request
End If

WebRequest.Secure

Secure As Boolean

Indicates if the request came in over a secure channel.

This property is read-only.

Method descriptions

WebRequest.Cookie

Cookie(name As String) As String

Returns the cookie using the specified Name or an empty string if no such cookie exists.


WebRequest.Header

Header(name As String) As String

Gets or sets a request header using the specified Name. Setting a header to a blank string removes the header.


WebRequest.HeaderNames

HeaderNames As String()

Returns and array of all header names.


WebRequest.Parameter

Parameter(name As String) As String

Returns the parameter value using the specified Name or an empty string if no such parameter exists.


WebRequest.Reset

Reset

Resets the request object back to its original state.

Notes

You are most likely to use this in conjunction with the WebApplication.HandleURL event handler. This event handler supplies a parameter (Request As WebRequest) that you can use to process the incoming request and send out a reply.

Compatibility

Web projects on all supported operating systems.

See also

Object parent class; WebApplication.HandleURL event and WebResponse class.