This module implements protocol functions that use the libcurl library to fetch data from external HTTP servers or post data to HTTP servers. The module is using a concept of "connections" to define properties of HTTP sessions in a simple way. A connection has one or multiple servers and a set of settings that apply to the specific connection. The http_client module has multiple settings, some of them apply to a defined connection. You can set timeouts, max data sizes for download and much more either using modparam settings or parameters to the connection definition. The connections can either be defined with the "httpcon" module parameter or in a separate configuration file, as specified by the "config_file" module parameter. Like in SIP, the HTTP URL may need encoding to be transported safely over the network. Check the string encoding functions in the Transformation Cookbook (as used in the http_client_query() example below). The function http_client_query() allows Kamailio to issue an HTTP GET request and get access to parts of the reply. This function has been ported from the utils module and now use the same libcurl functions. We recommend using the new functionality provided by this module. The http_client module uses the CURL library setting up connections. The CURL library by default use the system configured DNS resolvers, not the Kamailio resolver. The module is limited to using HTTP and HTTPS protocols.
| Parámetro | Tipo | Descripción |
|---|---|---|
| httpredirect | int | 3.2. httpproxy (string) 3.3. httpproxyport (string) 3.4. useragent (string) 3.5. maxdatasize (int) 3.6. connection_timeout (int) 3.7. timeout_mode (int) 3.8. client_cert (string) 3.9. client_key (stri |
| httpproxy | string | 3.3. httpproxyport (string) 3.4. useragent (string) 3.5. maxdatasize (int) 3.6. connection_timeout (int) 3.7. timeout_mode (int) 3.8. client_cert (string) 3.9. client_key (string) 3.10. cacert (string |
| httpproxyport | string | 3.4. useragent (string) 3.5. maxdatasize (int) 3.6. connection_timeout (int) 3.7. timeout_mode (int) 3.8. client_cert (string) 3.9. client_key (string) 3.10. cacert (string) 3.11. cipher_suites (strin |
| useragent | string | 3.5. maxdatasize (int) 3.6. connection_timeout (int) 3.7. timeout_mode (int) 3.8. client_cert (string) 3.9. client_key (string) 3.10. cacert (string) 3.11. cipher_suites (string) 3.12. verify_peer (in |
| maxdatasize | int | 3.6. connection_timeout (int) 3.7. timeout_mode (int) 3.8. client_cert (string) 3.9. client_key (string) 3.10. cacert (string) 3.11. cipher_suites (string) 3.12. verify_peer (int) 3.13. verify_host (i |
| connection_timeout | int | 3.7. timeout_mode (int) 3.8. client_cert (string) 3.9. client_key (string) 3.10. cacert (string) 3.11. cipher_suites (string) 3.12. verify_peer (int) 3.13. verify_host (int) 3.14. tlsversion (int) 3.1 |
| timeout_mode | int | 3.8. client_cert (string) 3.9. client_key (string) 3.10. cacert (string) 3.11. cipher_suites (string) 3.12. verify_peer (int) 3.13. verify_host (int) 3.14. tlsversion (int) 3.15. authmethod (int) 3.16 |
| client_cert | string | 3.9. client_key (string) 3.10. cacert (string) 3.11. cipher_suites (string) 3.12. verify_peer (int) 3.13. verify_host (int) 3.14. tlsversion (int) 3.15. authmethod (int) 3.16. keep_connections (int) 3 |
| client_key | string | 3.10. cacert (string) 3.11. cipher_suites (string) 3.12. verify_peer (int) 3.13. verify_host (int) 3.14. tlsversion (int) 3.15. authmethod (int) 3.16. keep_connections (int) 3.17. query_result (int) 3 |
| cacert | string | 3.11. cipher_suites (string) 3.12. verify_peer (int) 3.13. verify_host (int) 3.14. tlsversion (int) 3.15. authmethod (int) 3.16. keep_connections (int) 3.17. query_result (int) 3.18. query_maxdatasize |
| cipher_suites | string | 3.12. verify_peer (int) 3.13. verify_host (int) 3.14. tlsversion (int) 3.15. authmethod (int) 3.16. keep_connections (int) 3.17. query_result (int) 3.18. query_maxdatasize (int) 3.19. httpcon (string) |
| verify_peer | int | 3.13. verify_host (int) 3.14. tlsversion (int) 3.15. authmethod (int) 3.16. keep_connections (int) 3.17. query_result (int) 3.18. query_maxdatasize (int) 3.19. httpcon (string) 3.20. config_file (stri |
| verify_host | int | 3.14. tlsversion (int) 3.15. authmethod (int) 3.16. keep_connections (int) 3.17. query_result (int) 3.18. query_maxdatasize (int) 3.19. httpcon (string) 3.20. config_file (string) 3.21. netinterface ( |
| tlsversion | int | 3.15. authmethod (int) 3.16. keep_connections (int) 3.17. query_result (int) 3.18. query_maxdatasize (int) 3.19. httpcon (string) 3.20. config_file (string) 3.21. netinterface (string) 3.22. response_ |
| authmethod | int | 3.16. keep_connections (int) 3.17. query_result (int) 3.18. query_maxdatasize (int) 3.19. httpcon (string) 3.20. config_file (string) 3.21. netinterface (string) 3.22. response_headers (int) |
| keep_connections | int | 3.17. query_result (int) 3.18. query_maxdatasize (int) 3.19. httpcon (string) 3.20. config_file (string) 3.21. netinterface (string) 3.22. response_headers (int) |
| query_result | int | 3.18. query_maxdatasize (int) 3.19. httpcon (string) 3.20. config_file (string) 3.21. netinterface (string) 3.22. response_headers (int) |
| query_maxdatasize | int | 3.19. httpcon (string) 3.20. config_file (string) 3.21. netinterface (string) 3.22. response_headers (int) |
| httpcon | string | 3.20. config_file (string) 3.21. netinterface (string) 3.22. response_headers (int) |
| config_file | string | 3.21. netinterface (string) 3.22. response_headers (int) |
| netinterface | string | 3.22. response_headers (int) |
| response_headers | int | The parameters are loaded in order. That can lead to unexpected behavior: If httpcon is set at first, the default values for all other parameters are used, and not the values that might be set after h |
| httpredirect | int | If set to 1, enabled, http_client will follow HTTP 302 Redirects. If set to 0, http_client will not follow redirects. Default is 1, enabled. |
| httpproxy | string | URL for a HTTP proxy to use as a default proxy for all connections. |
| httpproxyport | string | Port number for a HTTP proxy to use as a default proxy port for all connections. |
| useragent | string | Useragent to use in the HTTP protocol for requests. Defaults to the Kamailio SIP useragent string - including software version and platform. |
| maxdatasize | int | Defines the maximum size in bytes for a response. Note that this is allocated from pkg memory (process memory) dynamically. |
| connection_timeout | int | Defines how long Kamailio waits for response from servers. Value is expressed in seconds or milliseconds, depending on parameter timeout_mode. |
| timeout_mode | int | Defines if timeouts are enabled, and in which unit timeout values are expressed. |
| client_cert | string | File name for a TLS client certificate. The certificate needs to be encoded in PEM format. |
4.2. http_connect_raw(connection, url, content_type, data, result) 4.3. http_get_redirect(connection, result) 4.4. http_client_query(url, [post-data], [hdrs], result) 4.5. http_client_get(url, body, hdrs, respv) 4.6. http_client_request(met, url, bod
4.3. http_get_redirect(connection, result) 4.4. http_client_query(url, [post-data], [hdrs], result) 4.5. http_client_get(url, body, hdrs, respv) 4.6. http_client_request(met, url, body, hdrs, respv) 4.7. http_client_request_v2pk(met, url, body, hdrs,
4.4. http_client_query(url, [post-data], [hdrs], result) 4.5. http_client_get(url, body, hdrs, respv) 4.6. http_client_request(met, url, body, hdrs, respv) 4.7. http_client_request_v2pk(met, url, body, hdrs, respv) 4.8. http_client_response_headers_s
4.5. http_client_get(url, body, hdrs, respv) 4.6. http_client_request(met, url, body, hdrs, respv) 4.7. http_client_request_v2pk(met, url, body, hdrs, respv) 4.8. http_client_response_headers_set(mode) 4.9. http_client_response_headers_clear()
4.6. http_client_request(met, url, body, hdrs, respv) 4.7. http_client_request_v2pk(met, url, body, hdrs, respv) 4.8. http_client_response_headers_set(mode) 4.9. http_client_response_headers_clear()
4.7. http_client_request_v2pk(met, url, body, hdrs, respv) 4.8. http_client_response_headers_set(mode) 4.9. http_client_response_headers_clear()
4.8. http_client_response_headers_set(mode) 4.9. http_client_response_headers_clear()
4.9. http_client_response_headers_clear()
4.1. http_connect(connection, url, [content_type, data,] result)
Sends HTTP GET or POST request to a given connection. For a POST request, content-type can be specified. * connection - the name of an existing HTTP connection, defined by a httpcon modparam. url - the part of the URL to add to the predefined URL in
usage ... modparam("http_client", "httpcon", "apiserver=>https://kamailio.org/api/"); ... # POST Request $var(res) = http_connect("apiserver", "/mailbox", "application/json", "{ ok, {20 0, ok}}", "$avp(gurka)"); xlog("L_INFO", "API-server HTTP connec
Sends HTTP POST request to a given connection. Similar to http_connect. The only difference is that the data parameter will not be parsed for pseudo variables, therefore it can safely be used for content that may contain "$" character like JSON. * co
usage ... modparam("http_client", "httpcon", "apiserver=>https://kamailio.org/api/"); ... # POST Request $var(res) = http_connect_raw("apiserver", "/mailbox", "application/json", "{ ok, {200, ok}}", "$avp(gurka)"); xlog("L_INFO", "API-server HTTP con
When a http connection gets a redirect and the connection is configured to follow redirects (301,302) then the target URL, the result of the redirects can be retrieved with this function after a successful connection. * connection - the name of an ex
usage ... modparam("http_client", "httpredirect", 1); ... http_get_redirect("apiserver", "$var(targeturl)"); ...
Sends HTTP GET or POST request according to URL given in “url” parameter, which is a string that may contain pseudo variables.
usage ... # GET-Request http_client_query("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$( fu{s.escape.param})", "$var(result)"); switch ($rc) { ... } ... # POST-Request http_client_query("http://api.com/index.php", "r_uri=$(ru{s.escape
Perform a HTTP GET request to "url", storing the response body in the "respv" variable. The "body" and "hdrs" can be empty strings to skip setting them. The first three parameters can contain variables that are evaluated at runtime. The "respv" has t
usage ... http_client_get("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu {s.escape.param})", "", "X-Token: abc", "$var(result)"); switch ($rc) { ... } ...
Perform a HTTP request to "url", storing the response body in the "respv" variable. The method of the request is set by "met". The "body" and "hdrs" can be empty strings to skip setting them. The first four parameters can contain variables that are e
usage ... http_client_request("GET", "http://api.com/index.php?r_uri=$(ru{s.escape.param}) &f_uri=$(fu{s.escape.param})", "", "X-Token: abc", "$var(result)"); switch ($rc) { ... } ...
Similar to http_client_request(), but using HTTP/2 prior-knowledge that the server does not need HTTP/1.1-Upgrade (direct HTTP/2 by seting libcurl option CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE).
usage ... http_client_request_v2pk("GET", "http://api.com/index.php?r_uri=$(ru{s.escape.pa ram})&f_uri=$(fu{s.escape.param})", "", "X-Token: abc", "$var(result)"); switch ($rc) { ... } ...
Set if the HTTP response header should be stored (when mode is 1) or not (when mode is 0). If mode is 0, then it also clears previously stored response headers.
usage ... http_client_response_headers_set("1"); http_client_request_v2pk("GET", "http://api.com/index.php?r_uri=$(ru{s.escape.pa ram})&f_uri=$(fu{s.escape.param})", "", "X-Token: abc", "$var(result)"); xinfo("response header: $httprhdr(X-Header)\n")
Copyright © 2008-2009 Juha Heinanen
Copyright © 2013 Carsten Bock, ng-voice GmbH
Copyright © 2015 Olle E. Johansson, Edvina AB
Copyright © 2016 Hugh Waite, Xura Inc