HTTPMethod

Command group Flag affected Reversible Execute on client Platform(s)
External commands YES NO NO All

Syntax

HTTPMethod (socket, uri, method, requesthdrlist, requestcontent, responsestatuscode, responsehdrrow, responsecontentReturns status

Description

Note: The flag is set according to whether Omnis was able to make a call to this external command.

HTTPMethod is a new client command that submits to a Web Server an HTTP request to execute a specified HTTP method.

This Web command requires an existing socket opened with HTTPOpen in order to submit the request. Note that this allows you to sequentially submit more than one request using the same socket connection subject to the rules of HTTP e.g. if the server returns a connection close header in its response, no more requests can be sent on the connection: at this point you need to use HTTPClose to free the socket resources and open a new connection if you want to send more requests to the server. Re-using a connection like this can be a significant performance improvement, especially when using a secure connection, where the connection set-up time is relatively costly.

Socket is a long integer field containing the socket number of an open HTTP connection.

URI is a Character field containing the URI to which the request is addressed. For example, "/default.html", or "/cgi-bin/mycgiscript". Note that if you wish to send query string parameters you must append them to the URI, using the standard ? syntax, e.g. "/default.html?name=test&value=good". You should encode these parameter names and values using CGIEncode.

Method is a Character field containing the HTTP method to be executed. Note that the method is case-sensitive. Standard HTTP methods such as GET and POST need to be specified in upper case.

RequestHdrList is an Omnis list with two character columns. The list contains the HTTP headers to send to the server. HTTPMethod automatically adds a content-length header if you do not specify it in this list, and RequestContent is supplied and not empty.

For example:

Header name Value
User-Agent My Client
Content-type text/html

RequestContent is the content to send to the server with the request. It only makes sense to send content with certain methods, e.g. POST. You can supply either character data, which the command converts to UTF-8 before sending, or binary data.

ResponseStatusCode is an integer field into which Omnis returns the HTTP status code of the HTTP request, e.g. 200 for success.

ResponseHdrRow is a row variable which Omnis populates with the headers received in the response from the server. HTTPMethod clears the row and adds columns as necessary. The column name is the header name converted to lower case, with any - characters removed. In addition, if there are headers with the same name,they are combined into a single header with that name,with comma-separated values.

ResponseContent is a binary or character field into which the command stores the content (if any) received in the response from the server. If this is a character field, the command assumes the content is UTF-8 encoded, and converts from UTF-8 to character before storing the response in the field.

Status is an Omnis Long Integer field which receives the value zero for success, or an error code < 0 for failure.