# OpenEuphoria Manual

## Euphoria v4.1

routine or constant name search

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.38 DNS | Up: 8 API Reference | 8.40 URL handling > | 9 Release Notes >>

## 8.39 HTTP Client

### 8.39.1 Error Codes

#### 8.39.1.1 ERR_MALFORMED_URL

    include std/net/http.e
    namespace http
    public enum ERR_MALFORMED_URL

#### 8.39.1.2 ERR_INVALID_PROTOCOL

    include std/net/http.e
    namespace http
    public enum ERR_INVALID_PROTOCOL

#### 8.39.1.3 ERR_INVALID_DATA

    include std/net/http.e
    namespace http
    public enum ERR_INVALID_DATA

#### 8.39.1.4 ERR_INVALID_DATA_ENCODING

    include std/net/http.e
    namespace http
    public enum ERR_INVALID_DATA_ENCODING

#### 8.39.1.5 ERR_HOST_LOOKUP_FAILED

    include std/net/http.e
    namespace http
    public enum ERR_HOST_LOOKUP_FAILED

#### 8.39.1.6 ERR_CONNECT_FAILED

    include std/net/http.e
    namespace http
    public enum ERR_CONNECT_FAILED

#### 8.39.1.7 ERR_SEND_FAILED

    include std/net/http.e
    namespace http
    public enum ERR_SEND_FAILED

#### 8.39.1.8 ERR_RECEIVE_FAILED

    include std/net/http.e
    namespace http
    public enum ERR_RECEIVE_FAILED

### 8.39.2 Constants

#### 8.39.2.1 FORM_URLENCODED

    include std/net/http.e
    namespace http
    public enum FORM_URLENCODED

#### 8.39.2.2 MULTIPART_FORM_DATA

    include std/net/http.e
    namespace http
    public enum MULTIPART_FORM_DATA

#### 8.39.2.3 ENCODE_NONE

    include std/net/http.e
    namespace http
    public enum ENCODE_NONE

No encoding is necessary

#### 8.39.2.4 ENCODE_BASE64

    include std/net/http.e
    namespace http
    public enum ENCODE_BASE64

Use Base64 encoding

### 8.39.3 Configuration Routines

#### 8.39.3.1 set_proxy_server

    include std/net/http.e
    namespace http
    public procedure set_proxy_server(sequence ip, integer port)

Configure http client to use a proxy server

##### Parameters:

- `proxy_ip` - IP address of the proxy server
- `proxy_port` - Port of the proxy server

### 8.39.4 Get/Post Routines

#### 8.39.4.1 http_post

    include std/net/http.e
    namespace http
    public function http_post(sequence url, object data, object headers = 0,
            natural follow_redirects = 10, natural timeout = 15)

Post data to a HTTP resource.

##### Parameters:

- `url` - URL to send post request to
- `data` - Form data (described later)
- `headers` - Additional headers added to request
- `follow_redirects` - Maximum redirects to follow
- `timeout` - Maximum number of seconds to wait for a response

##### Returns:

An integer error code or a 2 element sequence. Element 1 is a sequence of key/value pairs representing the result header information. element 2 is the body of the result.

If result is a negative integer, that represents a local error condition.

If result is a positive integer, that represents a HTTP error value from the server.

##### Data Sequence:

This sequence should contain key value pairs representing the expected form elements of the called URL. For a simple url-encoded form:

    { {"name", "John Doe"}, {"age", "22"}, {"city", "Small Town"}}

All Keys and Values should be a sequence.

If the post requires multipart form encoding then the sequence is a little different. The first element of the data sequence must be MULTIPART_FORM_DATA. All subsequent field values should be key/value pairs as described above except for a field representing a file upload. In that case the sequence should be:

`{ FIELD-NAME, FILE-VALUE, FILE-NAME, MIME-TYPE, ENCODING-TYPE }`

Encoding type can be

- ENCODE_NONE
- ENCODE_BASE64

An example for a multipart form encoded post request data sequence

    {
      { "name", "John Doe" },
      { "avatar", file_content, "me.png", "image/png", ENCODE_BASE64 },
      { "city", "Small Town" }
    }

##### See Also:

http_get

#### 8.39.4.2 http_get

    include std/net/http.e
    namespace http
    public function http_get(sequence url, object headers = 0, natural follow_redirects = 10,
            natural timeout = 15)

Get a HTTP resource.

##### Returns:

An integer error code or a 2 element sequence. Element 1 is a sequence of key/value pairs representing the result header information. Element 2 is the body of the result.

If result is a negative integer, that represents a local error condition.

If result is a positive integer, that represents a HTTP error value from the server.

##### Example:

    include std/console.e -- for display()
    include std/net/http.e

    object result = http_get("http://example.com")
    if atom(result) then
       printf(1, "Web error: %d\n", result)
        abort(1)
    end if

    display(result[1]) -- header key/value pairs
    printf(1, "Content: %s\n", { result[2] })

##### See Also:

http_post

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.38 DNS | Up: 8 API Reference | 8.40 URL handling > | 9 Release Notes >>