How can we help?

AxSms.HttpServer


Introduction

Skip to properties and methods

The HttpServer object is a secure HTTP(S) Server that is intended to be used to implement the server side of modern REST API’s or GRAPH API’s.

Many HTTP SMS providers require you to be able to receive HTTP API calls to receive SMS messages or delivery or status reports. This is easy to do with this HttpServer API.

Run a ‘Hello World’ Server

This example returns a ‘Hello World!’ page if you navigate to it with the browser and prints some request information on the console.

With this example no extra configuration and no elevated privileges are required to run it. You’ll only able to access this page from the same host that runs the example.

Set objHttpServer = CreateObject("AxSms.HttpServer")

WScript.Echo objHttpServer.Module & ": " & objHttpServer.Version

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

objHttpServer.AddUrl "http://localhost:8002/"
WScript.Echo "AddUrl: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & objHttpServer.RequestUrl & "]"
    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.ResponseBodyString = "<h1>Hello, World!</h1>"
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

objHttpServer.Shutdown
How to run this example

HTTP.sys and port sharing

Under the hood the HttpServer API makes use of the Microsoft Windows HTTP.sys HTTP module. HTTP.sys is a Microsoft Windows kernel module that is present in all recent versions of the Windows operating system. This is the same HTTP API that is also used by Microsoft IIS.

An important benefit of using the HTTP.sys API is the ability to do port sharing. This means that you will be able to run multiple instances of the HttpServer object on the same port as long as they use a different virtual path.

This ideal for implementing different end-points on the same server port in different processes. Meaning that only one port needs to be exposed through your firewall while you can still have the robustness and modularity of splitting up your service into multiple smaller services.

Configuration with Netsh

The configuration of the HttpServer module is done through the ‘Netsh http’ command.

This command is available by default on all recent Microsoft Windows desktop and server operating systems.

Use Netsh to setup access rights to a URL if it should be publicly available and to setup certificate bindings to use secure HTTPS.

Access control with Netsh

Register a URL that can be accessed through any IP on port 80 for user DOMAIN\user.

netsh http add urlacl url=https://+:80/api/receive-sms/ user=DOMAIN\user

Always end the URL on a trailing slash. After registering the URL for user DOMAIN\user they can listen to it or any virtual sub directory of it using the HttpServer object.

If your IP is local (i.e. localhost, 127.0.0.1 or ::1) and port is > 1024 and the protocol is http then this registration is not always necessary.

‘+’ is a wildcard meaning: ‘any IP address’.

Certificates with Netsh to use HTTPS

Setup a certificate to use for any IPv4 IP address.

netsh http add sslcert ipport=0.0.0.0:80 certhash=497da52026111053c644c5c1f19311917c30d614 appid={00112233-4455-6677-8899-AABBCCDDEEFF}

‘0.0.0.0’ is a wildcard used for any IPv4 address. Use [::] to represent any IPv6 address.

The certificate is identified by certhash, which is the same as ‘thumbprint’. You can find the thumbprint for a certificate in the windows management console (mmc) by clicking on a certificate and going the the ‘Details’ tab.

The appid can be any valid GUID that represents you application. For instance the APPID from your setup or anything else if you don’t have a setup.

Properties and Methods

Property Type Read/Write Description
Version String Read Version number of the SMS Component
Build String Read Build number of the SMS Component
Module String Read Module name of the SMS Component
LicenseStatus String Read License Status
LicenseKey String Read/Write License Key
LastError Number Read Result of the last called method
LogFile String Read/Write The path to a logfile which can be used for troubleshooting
ResponseCode Integer Read/Write HTTP response code
ResponseReason String Read/Write HTTP response reason
ResponseBodyString String Read/Write The response body to sent
ResponseHeaders String Read All response headers that would be sent
ResponseBodyBase64 String Read The response body to be sent as base64
RequestUrl String Read The Request URL
RequestUrlPath String Read The Request URL path part
RequestUrlHost String Read The Request URL host part
RequestUrlQueryString String Read The Request URL query string part
RequestVerb String Read The Request verb
RequestBodyString String Read The request body as a string
RequestBodyBase64 String Read The request body as base64
RequestBodyIsBinary Boolean Read True if the request body is binary
RequestIp String Read IP Address of the client
RequestPort String Read Port number of the client
RequestHeaders String Read All request headers
MaxRequestSizeBytes Number Read/Write Set the maximum request size
ResponseTimeoutMs Number Read/Write Response timeout in milliseconds
NumRequestQueues Number Read/Write Number of request queues

Method Description
Clear Reset all properties to their default values
SaveLicenseKey Save the License Key in the registry
GetErrorDescription Get the description of the given error
Sleep Sleep for the specified number of milliseconds
Startup Startup the HTTP Server
Shutdown Shutdown the HTTP Server
AddUrl Add a URL to listen to
WaitForRequest Wait for incoming HTTP(S) request
SendResponse Send a response to the last received request
ClearResponse Clears the response properties
LoadResponseBody Load a response body from file
SetResponseBodyFromBase64 Set the response body from a base64 string
SetResponseHeader Set a response HTTP header
GetResponseHeader Get a response HTTP header
SaveRequestBody Save request body to file
GetRequestHeader Get request header

Version property

Return the version number of the SMS Component

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")
WScript.Echo "SMS Component Version " & objHttpServer.Version & "; Build " & _
  objHttpServer.Build & "; Module " & objHttpServer.Module
WScript.Echo "License Status: " & objHttpServer.LicenseStatus & vbCrLf
...

Build property

Return the build number of the SMS Component.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")
WScript.Echo "SMS Component Version " & objHttpServer.Version & "; Build " & _
  objHttpServer.Build & "; Module " & objHttpServer.Module
WScript.Echo "License Status: " & objHttpServer.LicenseStatus & vbCrLf
...

Module property

Return the module name of the SMS Component.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")
WScript.Echo "SMS Component Version " & objHttpServer.Version & "; Build " & _
  objHttpServer.Build & "; Module " & objHttpServer.Module
WScript.Echo "License Status: " & objHttpServer.LicenseStatus & vbCrLf
...

LicenseStatus property

The status of your license. In case you have not licensed the product, the property holds the trial expiration date. For details, see Product Activation.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")               ' Create new instance
WScript.Echo "License Status: " & objHttpServer.LicenseStatus
WScript.Echo "License Key: " & objHttpServer.LicenseKey

LicenseKey property

A license key is required to unlock this component after the trial period has expired. Assign the LicenseKey property every time a new instance of this component is created (see code below). Alternatively, the LicenseKey property can be set automatically. This requires the license key to be stored in the registry. For details, see Product Activation.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")               ' Create new instance
objHttpServer.LicenseKey = "XXXXX-XXXXX-XXXXX"               ' Assign your license key 
WScript.Echo "LicenseKey: " & objHttpServer.LicenseKey

LastError property

Completion code of the last called method. To find the error description of a given error code, go to the online error codes codes page.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")  
...  
objHttpServer.Startup
WScript.Echo "Startup: [" & 
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
...

LogFile property

By default, LogFile holds an empty string and nothing is logged. If a valid file name is assigned to it, the SMS Component will write debug information to this file. Output data is written at the end of the file, the file is not cleared.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")  
...  
objHttpServer.LogFile = "log.txt"

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
...

ResponseCode property

The HTTP response code.

This information will be sent in response to the last received request when calling SendResponse.

Common HTTP response codes are:

Code Reason Description
200 OK Request was handles successfully
201 Created Resource was created; Normally after POST request.
301 Moved Permanently The URL of this resource has changed. New URL is in the response body.
400 Bad Request The server could not understand the request
401 Unauthorized The client is not logged in
403 Forbidden The client does not have access to this resource
404 Not Found The requested resource was not found
500 Internal Server Error An error occured at the server side

Find more response codes here

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    ... 
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.ResponseBodyString = "<h1>Hello, World!</h1>"
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

ResponseReason property

The HTTP response reason. This is a short descriptive text that accompanies the response code.

This information will be sent in response to the last received request when calling SendResponse.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    ... 
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.ResponseBodyString = "<h1>Hello, World!</h1>"
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

ResponseBodyString property

The full response body text that should be sent.

This information will be sent in response to the last received request when calling SendResponse.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    ... 
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.ResponseBodyString = "<h1>Hello, World!</h1>"
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

ResponseHeaders property

A string containing all response headers that would be sent. These are all set using SetResponseHeader.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    ... 
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    WScript.Echo objHttpServer.ResponseHeaders

    ...

  End If
WEnd

ResponseBodyBase64 property

The full response body that should be sent as base64. This is only set if SetResponseBodyFromBase64 is used.

This information will be sent in response to the last received request when calling SendResponse.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    ' return a single blue pixel
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "image/png"
    objHttpServer.SetResponseBodyFromBase64 = _
      "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACXBIWXMAAAAUAAAAFAFcjIF8AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm"

    WScript.Echo objHttpServer.ResponseBodyBase64
    
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

...

RequestUrl property

The request URL part of the last received request.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestUrlPath property

Only the path of the last received request URL.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestUrlHost property

Only the host part of the last received request URL.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestUrlQueryString property

Only the query string part of the last received request URL.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestVerb property

The request verb of the last received request URL.

This is the requested operation. Commonly used verbs are:

Verb Description
GET Get a resource (page, image, etc..) from the server.
POST Post data to the server. Commonly used to perform an action or store data.
PUT Mostly used for WEB API’s (REST or GRAPH) for updating existing data.
PATCH Mostly used for WEB API’s (REST or GRAPH) for modifying existing data.
DELETE Mostly used for WEB API’s (REST or GRAPH) for deleting existing data.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestBodyString property

The request body of the last received request as a string.

If the request body contains binary data this returns an empty string.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestBodyBase64 property

The request body of the last received request as a base64 encoded string.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Path: [" & objHttpServer.RequestUrlPath & "]"
    WScript.Echo "Request Host: [" & objHttpServer.RequestUrlHost & "]"
    WScript.Echo "Request Query: [" & objHttpServer.RequestUrlQueryString & "]"
    WScript.Echo "Request Verb: [" & objHttpServer.RequestVerb & "]"
    WScript.Echo "Request BodyString: [" & objHttpServer.RequestBodyString & "]"
    WScript.Echo "Request BodyBase64: [" & objHttpServer.RequestBodyBase64 & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo "Request Connection: [" & objHttpServer.GetRequestHeader("Connection") & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestBodyIsBinary property

This value is true if the last received request has a binary request body.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request IsBinary: [" & objHttpServer.RequestBodyIsBinary & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestIp property

The IP address that originated the last received request.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request IsBinary: [" & objHttpServer.RequestBodyIsBinary & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestPort property

The port number that originated the last received request.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request IsBinary: [" & objHttpServer.RequestBodyIsBinary & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

RequestHeaders property

All request headers of the last received request.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"

    WScript.Echo "From: [" & objHttpServer.RequestIP & "]: Port: [" & objHttpServer.RequestPort & "]"
    WScript.Echo "Request Headers: [" & objHttpServer.RequestHeaders & "]"
    WScript.Echo

    ... 
    
  End If
WEnd

MaxRequestSizeBytes property

Set the maximum request size.

Requests that exceed this size will be cancelled and will not be processed.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.MaxRequestSizeBytes = 10 * 1024 * 1024 ' 10MiB

WScript.Echo objHttpServer.Module & ": " & objHttpServer.Version

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

objHttpServer.AddUrl "http://localhost:8002/"
WScript.Echo "AddUrl: [" & _ 
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

ResponseTimeoutMs property

Set the response timeout in milliseconds. Applies to SendResponse.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.ResponseTimeout = 5000

WScript.Echo objHttpServer.Module & ": " & objHttpServer.Version

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

objHttpServer.AddUrl "http://localhost:8002/"
WScript.Echo "AddUrl: [" & _ 
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

NumRequestQueues property

This is the number simultaneous request queues that are allocated for this server.

The number of request queues is related to the maximum throughput for the HttpServer instance.

Default is 5

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.NumRequestQueues = 10

WScript.Echo objHttpServer.Module & ": " & objHttpServer.Version

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

objHttpServer.AddUrl "http://localhost:8002/"
WScript.Echo "AddUrl: [" & _ 
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

Clear method

This method resets all properties to their default values.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")   
....
objHttpServer.Clear
...

SaveLicenseKey method

Description:

Use SaveLicenseKey to store the license key permanently in the registry. When a license key is saved, it is restored automatically every time a new instance of the object (‘Smpp’) is created. It is not recommended to save the license key if you distribute the component with your own software, because the key can be easily used by others.

Parameters:

  • None.

Return value:

Always 0. Check LastError property to see if the method was completed successfully.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")               ' Create new instance
objHttpServer.LicenseKey = "XXXXX-XXXXX-XXXXX"
objHttpServer.SaveLicenseKey                                    ' Save license key to registry

For more information, see Product Activation.

GetErrorDescription method

GetErrorDescription provides the error description of a given error code.

Parameters:

  • The error code

Return value:

The error string.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")  
...  
objHttpServer.LogFile = "log.txt"

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
...

Sleep method

This method suspends the current thread for the specified number of milliseconds.

Parameters:

  • Milliseconds to sleep

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")
....
objHttpServer.Sleep 1000
...

Startup method

Starts the HTTP Server. Call this method before calling AddUrl.

Parameters:

  • none

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

WScript.Echo objHttpServer.Module & ": " & objHttpServer.Version

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

objHttpServer.AddUrl "http://localhost:8002/"
WScript.Echo "AddUrl: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

Shutdown method

Shutdown the HTTP Server and cleanup any resources that where in use.

Parameters:

  • none

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

WScript.Echo objHttpServer.Module & ": " & objHttpServer.Version

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

objHttpServer.AddUrl "http://localhost:8002/"
WScript.Echo "AddUrl: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

objHttpServer.Shutdown

AddUrl method

Add the given URL to the list of URLs to listen to while waiting for requests.

The URL should be fully qualified and end with a ‘/’ (e.g.: ‘http://localhost:8000/httpserver-test/’).

Make sure that your current user has permissions to listen to that URL. You can set these permissions using the ‘netsh http’ commandline.

Generally non-administrator users can only listen on local URLs (localhost, 127.0.0.1 or ::1) on ports larger than 1024.

To listen on a secure connection (HTTPS) make sure that you have used ‘netsh http’ to register a certificate with the given IP/port number combination of the URL.

Parameters:

  • URL

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

objHttpServer.AddUrl "http://localhost:8002/"
WScript.Echo "AddUrl: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

WaitForRequest method

Test for an existing request or wait a maximum amount of milliseconds for a new incoming HTTP(S) request.

Returns immediately if an HTTP(S) request is available.

If an HTTP(S) request was received LastError will be set to 0

When the timeout elapses without receiving a request LastError will be set to: 37008 (Timeout while waiting for requests).

Any other value for LastError means that there was an error during waiting for a request.

Use SendResponse to send a response.

Parameters:

  • Maximum nr of milliseconds to wait

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.ResponseBodyString = "<h1>Hello, World!</h1>"
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

...

SendResponse method

Send a response to the last received request. This method waits until either the response has timed out or was sent completely.

Prepare the response by setting the ‘Reponse…’ properties of this object.

To clear all of the ‘Reponse…’ properties use ClearResponse.

To send a valid response make sure that at least the ResponseCode property is set to a value.

Parameters:

  • none

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.ResponseBodyString = "<h1>Hello, World!</h1>"
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

...

ClearResponse method

Clears the ‘Response…’ properties of this object.

Parameters:

  • none

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & 
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.ResponseBodyString = "<h1>Hello, World!</h1>"
    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

...

LoadResponseBody method

Load a response body from file.

Parameters:

  • Full path
  • Is text file

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & 
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.LoadResponseBody "index.html", True
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If

    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

...

SetResponseBodyFromBase64 method

Set the response body from a base64 encoded string.

The HTTP Server component will decode the base64 and send the binary value.

Parameters:

  • Base64 string

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    ' return a single blue pixel
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "image/png"
    objHttpServer.SetResponseBodyFromBase64 = _
      "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACXBIWXMAAAAUAAAAFAFcjIF8AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm"

    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

...

SetResponseHeader method

Set a response HTTP header.

Use this function to set optional HTTP headers when needed.

The Content-Length header is set automatically so there’s no need to set that.

If a header with the same name is already present this method will overwrite that header. Header names are case-insensitive.

Parameters:

  • Header name
  • Header value

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    objHttpServer.ClearResponse
    objHttpServer.ResponseCode = 200
    objHttpServer.ResponseReason = "OK"
    objHttpServer.SetResponseHeader "Content-Type", "text/html"
    objHttpServer.LoadResponseBody "index.html", True
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Load reponse body error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If

    objHttpServer.SendResponse
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Send reponse error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If
  End If
WEnd

...

GetResponseHeader method

Get a response HTTP header value.

Use this function to get the value of optional HTTP headers that have previously been set.

Header names are case-insensitive.

Parameters:

  • Header name

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

...

objHttpServer.SetResponseHeader "Content-Type", "text/html"

...

sContentType = objHttpServer.GetResponseHeader("Content-Type")

...

SaveRequestBody method

Save the request body to file.

Parameters:

  • File path

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    objHttpServer.SaveRequestBody "Request.txt"
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Save request error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If

    ...
    
  End If
WEnd

...

GetRequestHeader method

Get a request header from the last received request.

The header name is case-insensitive

Parameters:

  • File path

Return value:

Always 0.

Example:

Set objHttpServer = CreateObject("AxSms.HttpServer")

objHttpServer.Startup
WScript.Echo "Startup: [" & _
  objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"

...

While objHttpServer.IsStarted
  objHttpServer.WaitForRequest(100)
  
  If objHttpServer.LastError = 0 Then
    WScript.Echo "Recieve request for: [" & _
      objHttpServer.RequestUrl & "]"
    WScript.Echo
    
    sConnection = objHttpServer.GetRequestHeader("Connection")
    If objHttpServer.LastError <> 0 Then 
      WScript.Echo "Get  error: [" & _
        objHttpServer.GetErrorDescription(objHttpServer.LastError) & "]"
      WScript.Quit 1
    End If

    WScript.Echo "Connection: [" & sConnection & "]"
    
    ...
    
  End If
WEnd

...