AxSms.Http
Introduction
Skip to properties and methods
A lot of bulk SMS providers or SMSC’s will provide a custom, HTTP based, interface to their customers to send out SMS messages.
Providers usually employ HTTP based custom interface because of their simplicity relative to more complex protocols like SMPP. Performance wise it’s roughly comparable to SMPP in medium to large volumes.
The drawback in using HTTP is that HTTP will only allow sending SMS messages. If the user needs to receive SMS messages or if the user needs to receive delivery reports the user will have to set up an HTTP server as well to receive HTTP requests from SMSC.
The Smpp object in the SMS Component is set up to support most HTTP providers. For simple provider configurations the user can set up Url and PostBody templates and use the SendSms method to send out SMS messages. For more complex configurations the Http object provides Post and Get methods to create your own URL / post body layout independent of the existing SMS message object.
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 |
WebAccount | String | Read/Write | Web login account if required |
WebPassword | String | Read/Write | Web password if required |
ProxyServer | String | Read/Write | ProxyServer URL if required |
ProxyAccount | String | Read/Write | Proxy login account if required |
ProxyPassword | String | Read/Write | Proxy password if required |
LastResponseCode | Number | Read | Last response code returned by the server |
RequestTimeout | Number | Read/Write | Request timeout in milliseconds |
Url | String | Read/Write | Default URL, including placeholders, when sending text messages |
PostBody | String | Read/Write | Default Post body, including placeholders, when sending text messages |
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 |
SetHeader | Set HTTP header to be sent |
Get | Get a web page |
Post | Post a post body to a web server |
Download | Download a file from a web server |
SendSms | Send a text message through this HTTP connection |
UrlEncode | URL encode the given string |
HexEncode | Hex encode the given string |
Base64Encode | Base64 encode the given string |
Base64EncodeFile | Base64 encode the given file |
Version property
Return the version number of the SMS Component
Example:
Set objHttp = CreateObject("AxSms.Http")
WScript.Echo "SMS Component Version " & objHttp.Version & "; Build " & _
objHttp.Build & "; Module " & objHttp.Module
WScript.Echo "License Status: " & objHttp.LicenseStatus & vbCrLf
...
Build property
Return the build number of the SMS Component.
Example:
Set objHttp = CreateObject("AxSms.Http")
WScript.Echo "SMS Component Version " & objHttp.Version & "; Build " & _
objHttp.Build & "; Module " & objHttp.Module
WScript.Echo "License Status: " & objHttp.LicenseStatus & vbCrLf
...
Module property
Return the module name of the SMS Component.
Example:
Set objHttp = CreateObject("AxSms.Http")
WScript.Echo "SMS Component Version " & objHttp.Version & "; Build " & _
objHttp.Build & "; Module " & objHttp.Module
WScript.Echo "License Status: " & objHttp.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 objHttp = CreateObject("AxSms.Http") ' Create new instance
WScript.Echo "License Status: " & objHttp.LicenseStatus
WScript.Echo "License Key: " & objHttp.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 objHttp = CreateObject("AxSms.Http") ' Create new instance
objHttp.LicenseKey = "XXXXX-XXXXX-XXXXX" ' Assign your license key
WScript.Echo "LicenseKey: " & objHttp.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 objHttp = CreateObject("AxSms.Http")
...
Set objMessage = CreateObject("AxSms.Message")
objMessage.ToAddress = "+31611223344"
objMessage.Body = "Short text message"
objHttp.SendSms objMessage
WScript.Echo "Send SMS result: " & objHttp.LastError ' Is our message sent ?
...
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 objHttp = CreateObject("AxSms.Http")
objHttp.LogFile = "C:\temp\log.txt"
...
Set objMessage = CreateObject("AxSms.Message")
objMessage.ToAddress = "+31611223344"
objMessage.Body = "Short text message"
objHttp.SendSms objMessage
...
WebAccount property
Set the web login account if this is required.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.WebAccount = "Account"
objHttp.WebPassword = "Password"
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WebPassword property
Set the web login password if this is required.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.WebAccount = "Account"
objHttp.WebPassword = "Password"
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
ProxyServer property
Set the proxy server if this is required.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.ProxyServer = "proxy.domain.com:8080"
objHttp.ProxyAccount = "Account"
objHttp.ProxyPassword = "Password"
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
ProxyAccount property
Set the proxy server login if this is required.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.ProxyServer = "proxy.domain.com:8080"
objHttp.ProxyAccount = "Account"
objHttp.ProxyPassword = "Password"
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
ProxyPassword property
Set the proxy server password if this is required.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.ProxyServer = "proxy.domain.com:8080"
objHttp.ProxyAccount = "Account"
objHttp.ProxyPassword = "Password"
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
LastResponseCode property
This property is set to the last response code received from the server.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo objSmpp.LastResponseCode
RequestTimeout property
This is the request timeout in milliseconds.
Default request timeout is 10000 milliseconds.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.RequestTimeout = 50000
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
Url property
This is the default URL that is being used when sending text messages trough Send Sms.
Use these placeholders to insert dynamic fields into the URL.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.Url = "http://gateway.auronsoftware.com:8080/sendsms/default.asp"
objHttp.PostBody = "username=CE658B84&password=FAC1982E&text=" & _
objConst.HTTP_PLACEHOLDER_BODY & "&to=" & objConst.HTTP_PLACEHOLDER_TOADDRESS
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
PostBody property
This is the default Post body that is being used when sending text messages trough Send Sms.
Use these placeholders to insert dynamic fields into the Post body.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.Url = "http://gateway.auronsoftware.com:8080/sendsms/default.asp"
objHttp.PostBody = "username=CE658B84&password=FAC1982E&text=" & _
objConst.HTTP_PLACEHOLDER_BODY & "&to=" & objConst.HTTP_PLACEHOLDER_TOADDRESS
...
objHttp.SendSms objMessage
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
Clear method
This method resets all properties to their default values.
Parameters:
- None
Return value:
Always 0.
Example:
Set objHttp = CreateObject("AxSms.Http")
....
objHttp.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 (‘Http’) 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 objHttp = CreateObject("AxSms.Http") ' Create new instance
objHttp.LicenseKey = "XXXXX-XXXXX-XXXXX"
objHttp.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 objHttp = CreateObject("AxSms.Http")
objHttp.LogFile = "C:\temp\log.txt"
...
Set objMessage = CreateObject("AxSms.Message")
objMessage.ToAddress = "+31611223344"
objMessage.Body = "Short text message"
objHttp.SendSms objMessage
WScript.Echo "SendSms result: " & objHttp.LastError & ", " & _
objHttp.GetErrorDescription(objHttp.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 objHttp = CreateObject("AxSms.Http")
....
objHttp.Sleep 1000
...
SetHeader method
Set a custom HTTP header which will be include in future requests or posts made to a web server. The header value will clear any header value of the same name that was previously set. To clear all header values call the Clear method.
Parameters:
- Header – Name of the header
- Value – Header value
Return value:
None
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.SetHeader("Content-Type", "application/x-www-form-urlencoded")
...
strResponse = objHttp.Post("http://gateway.auronsoftware.com:8080/sendsms/default.asp", _
"username=CE658B84&password=FAC1982E&text=" & objHttp.UrlEncode(objMessage.Body) & _
"&to=" & objHttp.UrlEncode(objMessage.ToAddress))
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo strResponse
...
Get method
Get the contents of a web page from a web server and return it as a string value. This method defaults to non secure connections using the default HTTP port 80.
The use of SSL or a different port can be specified as usual, e.g. https://cruisecontrol.intra:8080/dashboard connects securely on port 8080.
Parameters:
- URL
Return value:
The requested website as a string value.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
strResponse = objHttp.Get("http://gateway.auronsoftware.com:8080/sendsms/default.asp?" & _
"username=CE658B84&password=FAC1982E&text=" & objHttp.UrlEncode(objMessage.Body) & _
"&to=" & objHttp.UrlEncode(objMessage.ToAddress)
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo strResponse
...
Post method
Post a string to a website and returns the result as a string value. This method defaults to non secure connections using the default HTTP port 80. The use of SSL or a different port can be specified as usual, e.g. https://cruisecontrol.intra:8080/dashboard connects securely on port 8080.
Parameters:
- Url
- Post body
Return value:
The requested website as a string value.
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
strResponse = objHttp.Post("http://gateway.auronsoftware.com:8080/sendsms/default.asp", _
"username=CE658B84&password=FAC1982E&text=" & objHttp.UrlEncode(objMessage.Body) & _
"&to=" & objHttp.UrlEncode(objMessage.ToAddress))
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo strResponse
...
Download method
Download a text or binary file from a web server. Use this method to download image or other media files.
Parameters:
- Url
- Target path
Return value:
None
Example:
Set objHttp = CreateObject("AxSms.Http")
...
objHttp.Download("https://whatsapp.someprovider:8080/media/3hudu32o3ikdj44u.mp4", _
"c:\server\media\3hudu32o3ikdj44u.mp4")
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
...
SendSms method
This method sends an SMS through HTTP by replace the placeholders in the Url and PostBody parameters. If the PostBody parameter is not set it will use a ‘GET’ request type, otherwise a ‘POST’ request type will be used.
Parameters:
- SMS Message object
- (Optional) Multipart flag, can be one of these constants
Return value:
The server response
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
objHttp.Url = "http://gateway.auronsoftware.com:8080/sendsms/default.asp"
objHttp.PostBody = "username=CE658B84&password=FAC1982E&text=" & _
objConst.HTTP_PLACEHOLDER_BODY & "&to=" & objConst.HTTP_PLACEHOLDER_TOADDRESS
...
WScript.Echo objHttp.SendSms(objMessage)
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
UrlEncode method
Use this method to ‘URL encode’ parameters before adding them to the URL or Post body.
Parameters:
- The string to encode
Return value:
The encoded string
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
strResponse = objHttp.Get("http://gateway.auronsoftware.com:8080/sendsms/default.asp?" & _
"username=CE658B84&password=FAC1982E&text=" & objHttp.UrlEncode(objMessage.Body) & _
"&to=" & objHttp.UrlEncode(objMessage.ToAddress)
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo strResponse
...
HexEncode method
Use this method to ‘Hex’ encode strings before adding them as a GET argument or POST body.
Parameters:
- The string to encode
Return value:
The encoded string
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
strResponse = objHttp.Get("http://gateway.auronsoftware.com:8080/sendsms/default.asp?" & _
"username=CE658B84&password=FAC1982E&text=" & objHttp.HexEncode(objMessage.Body) & _
"&to=" & objHttp.HexEncode(objMessage.ToAddress)
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo strResponse
...
Base64Encode method
Use this method to Base64 encode a string.
Parameters:
- String to encode
Return value:
The encoded string
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
strResponse = objHttp.Get("http://post.httpprovider.com:8080/sendsms/default.asp?" & _
"username=Name&password=Password&text=" & objHttp.Base64Encode(objMessage.Body) & _
"&to=" & objHttp.UrlEncode(objMessage.ToAddress)
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo strResponse
...
Base64EncodeFile method
Use this method to Base64 encode a file
Parameters:
- The filename of the file to encode
Return value:
The encoded string
Example:
Set objHttp = CreateObject("AxSms.Http")
Set objMessage = CreateObject("AxSms.Message")
...
strResponse = objHttp.Get("http://post.httpprovider.com:8080/sendsms/default.asp?" & _
"username=Name&password=Password&image=" & objHttp.Base64EncodeFile("logo.png") & _
"&to=" & objHttp.UrlEncode(objMessage.ToAddress)
If objHttp.LastError <> 0 Then
WScript.Echo "Error: " & objHttp.GetErrorDescription(objHttp.LastError)
WScript.Quit 1
End If
WScript.Echo strResponse
...