UHTTP

The Uniface UHTTP component is an HTTP client that is used for sending and receiving HTTP requests and responses. It provides operations for executing HTTP requests used for web applications and RESTful web services.

You can use UHTTP operations to integrate communication with web sites, implement basic browser functionality, retrieve and store data in the cloud, and so on. The component signature is automatically available in Uniface, so you can create a new instance and activate its operations using handles.

The UHTTP component's SEND operation enables you to invoke HTTP methods (such as GET, POST, PUT, HEAD and DELETE) by submitting an HTTP request to a URL.

Other UHTTP operations enable you to prepare content and interpret responses, and to control the behavior of the SEND operation.

Operations

The UHTTP component API provides the following operations:

  • SEND—send an HTTP request using the specified HTTP method, such as PUT or POST for file upload and GET for file download.

  • SET_FLAGS—set flags prior to a SEND instruction to determine how Uniface handles HTTP communication. For example, you can specify whether requests can be redirected, determine how the component responds to mismatched or expired certificates for HTTPS, or calculate content length.

  • SET_TIMEOUT—set the amount of time an HTTP request can take to complete.

  • WRITE_CONTENT—append a segment of data to the UHTTP's content buffer, which will be used by the SEND operation. It cannot be used in combination with the file operations, such as LOAD_FILE_CONTENTS.

  • READ_CONTENT—obtain additional data from the last HTTP request. It cannot be used in combination with the file operations, such as DUMP_FILE_CONTENTS.

  • LOAD_FILE_CONTENTS—load a file, or part of a file, into the request body prior to calling SEND to upload the file.

  • DUMP_FILE_CONTENTS—create a local file by reading a response body containing the file, or a chunk of it.

  • GET_INFO—if required, get information about the request body either before or after the SEND operation. This is most useful when the request body represents the current file, as there is no other way of getting the file length or range.

  • GET_LAST_ERROR—return the last CURL error as an error string. Use it to troubleshoot an error caused by the SEND operation.

  • CLOSE_FILE—close the current file that was being used for chunked file transfer.

Configuring UHTTP

In the application assignment file, you can use settings and logicals to:

  • Configure a proxy server for HTTP transport. For more information, see [PROXY_SETTINGS].

  • Configure the default authentication scheme used for SEND requests. For more information, see UHTTP_DEF_AUTH.

  • Set default Content-Type header to be added to POST requests (Windows only). For more information, see UHTTP_WPOST_FORM.

Note:  The UHTTP component supports HTTPS data transport using libcurl. Local certificates must be stored in a ca-bundle.crt file. This file is not delivered as part of the installation, so you need to create it and copy it to the common\usys directory. For more information, see HTTPS Protocol.)

Using UHTTP

The following example shows how you can instantiate the UHTTP component and call its operations:

variables
   handle  vUHTTP
   numeric vStatus
   string  vURI, vHeaders, vContent, vResponse 
endvariables
newinstance "UHTTP", vUHTTP

vURI = "http://mysite.com/op1"

;Create list of headers 
putitem/id vHeaders, "Content-Type", "application/xml; charset=UTF-8"
putitem/id vheaders, "Accept-Charset", "ISO-8859-1 ; q = 0.4, UTF-16BE; q=0.9"

;Assemble content and assign to vContent ...
...

; Call the UHTTP.SEND operation
vStatus = vUHTTP->SEND(vURI, "POST", "", "", vHeaders, vContent, vResponse)
...

Related Topics