Open topic with navigation

# send_http_request

The `send_http_request` function sends an HTTP request.

## Syntax

    send_http_request( params )

## Arguments

Argument | Description
--- | ---
`params` | (table) Named parameters that configure the HTTP request. The table maps parameter names (string) to parameter values. For information about the parameters that you can set, see the following table.

## Named Parameters

Named Parameter | Description
--- | ---
`url` | (string) The full URL for the HTTP request. If you provide a URL, the other parameters used to build the URL are not used.
`method` | (string) The HTTP method to use (`GET`, `POST`, or `DELETE`). The default is `"GET"`.
`headers` | (table) A table of HTTP headers to send with the request. The table must map header names to values.
`content` | (string) For HTTP POST, the data to be sent with the post.
`site` | (string) The site to which the HTTP request is sent.
`port` | (integer) The port to which the HTTP request is sent. By default, the request is sent to port 80.
`uri` | (string) The URI to request.
`params` | (table) Additional parameters for the request. The table must map parameter names to parameter values.
`section` | (string) The name of a section in the configuration file that contains transport related parameters such as SSL or proxy settings.
`options` | (table) A table of HTTP client options to use for the request. For information about the options that you can set, see the following table.

## HTTP Client Options

Named Parameter | Description
--- | ---
`BasicOnAuthenticate` | A Boolean value that specifies whether to delay authentication. Some types of authentication (for example Siteminder) require that authentication is delayed until credentials are requested.
`BasicPassword` | The password to use to access resources protected by basic authentication.
`BasicUsername` | The username to use to access resources protected by basic authentication.
`DigestPassword` | The password to use to access resources protected by HTTP Digest authentication.
`DigestUsername` | The username to use to access resources protected by HTTP Digest authentication.
`EnableKerberos` | A Boolean value that specifies whether to use Kerberos authentication.
`GSSName` | The file name of the GSS library. This library is required to use Kerberos authentication.
`GSSPath` | The path to the folder that contains the GSS library. This library is required to use Kerberos authentication.
`HttpConnectTimeout` | The maximum amount of time to wait for an HTTP server to respond when establishing a connection (in seconds).
`HttpReadTimeout` | The maximum amount of time to wait to receive data from an HTTP server (in seconds).
`NTLMPassword` | The password to use to access resources protected by NTLM authentication.
`NTLMUsername` | The username to use to access resources protected by NTLM authentication.
`ProxyHost` | The host name or IP address of the proxy server to use.
`ProxyPassword` | The password to use to authenticate with the proxy server.
`ProxyPort` | The port of the proxy server to use.
`ProxyUsername` | The user name to use to authenticate with the proxy server.
`SSLMethod` | The SSL protocol to use. Refer to the documentation for the `SSLMethod` configuration parameter for a list of possible options.
`UserAgent` | The value to use for the user-agent request header.
`UseSPNEGO` | A Boolean value that specifies whether to use the SPNEGO protocol to decide which type of authentication to use.

## Returns

String. The HTTP response.

The `send_http_request` function can throw an exception if the request fails. You can catch an exception by calling `send_http_request` using the Lua function `pcall`.

## Examples

The following example shows how to make a simple request:

    local wikipedia_page = send_http_request(
       {url = "http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol"} )

The following example shows how to make the same request but catch any exceptions with the Lua `pcall` function:

    local result, response = pcall ( send_http_request,
       {url = "http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol"} )

When the `send_http_request` function is successful, the `result` variable is `true` and `response` contains the response. If an exception is thrown from `send_http_request`, the `result` variable is `false` and `response` contains the error message.

The following examples demonstrate how to add additional named parameters:

    local google_search = send_http_request(
       {site = "www.google.co.uk", port = 80, uri = "/search",
       params = {q = "http protocol", safe = "active"}} )

    local search = send_http_request(
       {site = "www.site.com", port = 80, uri = "/query",
       params = {text = "http headers", maxresults = "10"}
       headers = { Cache-Control = "no-cache" }} )

© Copyright 2019 Micro Focus or one of its affiliates | Send documentation feedback Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm