Up | TOC | Index | |||||
<< 7 Included Tools | < 8.36 DNS | Up: 8 API Reference | 8.38 URL handling > | 9 Release Notes >> |
8.37 HTTP Client
8.37.1 Error Codes
8.37.1.1 ERR_MALFORMED_URL
include std/net/http.e namespace http public enum ERR_MALFORMED_URL
8.37.1.2 ERR_INVALID_PROTOCOL
include std/net/http.e namespace http public enum ERR_INVALID_PROTOCOL
8.37.1.3 ERR_INVALID_DATA
include std/net/http.e namespace http public enum ERR_INVALID_DATA
8.37.1.4 ERR_INVALID_DATA_ENCODING
include std/net/http.e namespace http public enum ERR_INVALID_DATA_ENCODING
8.37.1.5 ERR_HOST_LOOKUP_FAILED
include std/net/http.e namespace http public enum ERR_HOST_LOOKUP_FAILED
8.37.1.6 ERR_CONNECT_FAILED
include std/net/http.e namespace http public enum ERR_CONNECT_FAILED
8.37.1.7 ERR_SEND_FAILED
include std/net/http.e namespace http public enum ERR_SEND_FAILED
8.37.1.8 ERR_RECEIVE_FAILED
include std/net/http.e namespace http public enum ERR_RECEIVE_FAILED
8.37.2 Constants
8.37.2.1 FORM_URLENCODED
include std/net/http.e namespace http public enum FORM_URLENCODED
8.37.2.2 MULTIPART_FORM_DATA
include std/net/http.e namespace http public enum MULTIPART_FORM_DATA
8.37.2.3 ENCODE_NONE
include std/net/http.e namespace http public enum ENCODE_NONE
No encoding is necessary
8.37.2.4 ENCODE_BASE64
include std/net/http.e namespace http public enum ENCODE_BASE64
Use Base64 encoding
8.37.3 Get/Post Routines
8.37.3.1 http_post
include std/net/http.e namespace http public function http_post(sequence url, object data, object headers = 0, integer follow_redirects = 10, integer 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
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:
8.37.3.2 http_get
include std/net/http.e namespace http public function http_get(sequence url, object headers = 0, integer follow_redirects = 10, integer 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:
Up | TOC | Index | |||||
<< 7 Included Tools | < 8.36 DNS | Up: 8 API Reference | 8.38 URL handling > | 9 Release Notes >> |