HTTP POST and GET Requests
You can use Call Setup Rules to query HTTP-based servers using the HTTP GET and HTTP POST request methods. The response from the HTTP server can be used for various functionality such as routing, or its data can be saved, for example, as a call/session variable to use in SIP message manipulations.
You can also use Call Setup Rules to notify the server of a specific condition, using HTTP POST notifications. In this case, the Call Setup Rule does not expect a response from the server for these HTTP message notifications.
Syntax:
■ | To refer to an HTTP response code received from the HTTP server: |
Http.Response.Status
This syntax is used in the 'Condition' field.
■ | To refer to the body in the HTTP response (string after the HTTP headers): |
Http.Response.Body
This syntax can be used in the following fields:
● | 'Request Key' |
● | 'Condition' |
● | 'Action Value' |
■ | To refer to a condition if an HTTP response exists: |
Http.Found
This syntax is used in the 'Condition' field.
■ | To refer to the body in the sent HTTP POST request: |
Http.Request.Body
This syntax can be used in the following fields:
● | 'Condition' |
● | 'Action Subject' (with 'Action Type' configured to Modify for changing the body value entirely, or Add for appending and concatenating the new body value to the existing body) |
● | 'Action Value' |
■ | To refer to the Content-Type header in the sent HTTP request: |
Http.Request.Content-Type
This syntax can be used in the following fields:
● | 'Condition' |
● | 'Action Subject' (with 'Action Type' configured to Modify) |
● | 'Action Value' |
For POST requests, the header is omitted by default; for GET requests, it is set to "html/text". Commonly used Content-Type values include "application/json", "application/octet-stream", "message/http", "html/text", and "application/x-www-form-urlencoded".
The HTTP server is configured as a Remote Web Service in the Remote Web Services table with the 'Type' parameter configured to General. The 'Request Type' parameter in the Call Setup Rules table must be configured to HTTP GET, HTTP POST Query, or HTTP POST Notification and the 'Request Target' to the name of the Remote Web Service (case-sensitive).
● | When the Call Setup Rule doesn't need to do any action after the HTTP request is sent (e.g., for HTTP POST notification requests), you can use the value None in the 'Action Type' field. |
● | Unlike HTTP GET requests which include all required data in the URL, HTTP POST requests typically include a URL and a message body. |
Examples of HTTP GET and POST Requests
Request |
Request Target |
Request |
Condition |
Action |
ActionType |
Action |
Description |
---|---|---|---|---|---|---|---|
Example 1 |
|||||||
HTTP GET |
MyHTTP-Server |
'?user='+param.call.src.user |
|
param.call.src.name |
Modify |
http.response.body |
Searches the server for the caller's user name and then modifies the From header (caller ID) in the outgoing SIP message, by adding the value (user name) obtained from the HTTP response body. |
Example 2 |
|||||||
HTTP GET |
MyHTTP-Server |
'?user='+param.call.src.user |
http.response.status=='200' and http.response.body regex <value>)(.*)(</value>) |
header.X-Info |
Add |
$2 |
Searches the server for the caller's user name and if the HTTP response code is 200 OK, it then adds the "X-Info" header with the value obtained from the HTTP response body (value is taken from a position defined by regex), in the outgoing SIP message. |
Example 3 |
|||||||
None |
|
|
Param.Call.Dst.User != '911' |
|
Exit |
True |
If the destination number is not 911, then exit the Call Setup Rules table. |
None |
|
|
|
Http.Request.Content-Type |
Modify |
'application/json' |
Changes the HTTP GET request's Content-Type header value to the string value configured in the 'Action Value' field. |
None |
|
|
|
Http.Request.Body |
Modify |
'EmergencyCaller='+param.call.src.user |
Changes the HTTP GET request's body string value to the string value configured in the 'Action Value' field. |
HTTP POST Notification |
MyHTTP-Server |
'emergencyNotifier' |
|
|
None |
|
Sends an HTTP POST request to notify the HTTP server. |