Welcome Guest | My Membership | Login

IS.HTTPCLIENT - Using UniVerse and UniData UniBASIC Sockets



UniVerse and UniData includes support for both normal sockets and SSL sockets, in addition to the CallHTTP extension. The UniVerse and UniData CallHTTP UniBASIC extensions do what most developers needed when making SOAP or REST calls, but they do not support custom Authorization Headers. In order to work around this issue, a developer is requires to create the HTTP protocol manually.

UniBASIC provides support for both normal and SSL sockets, so developers have the ability to access both Http:// and Https:// without requiring an external OS routine.

The subroutine included with this article removes the complexity writing the HTTP protocol yourself by creating a single subroutine that you can call.

    This is the HTTP Method you are asking the web server to process. Normally, this is either 'GET' or 'POST'
  • URL
    This is the "Http://" or "Https://" want to request data from or send data to.
  • HEADER.DATA<1,n>
    Http Request Header Name - This is the header name that the developer wants to included with the request to the server.
  • HEADER.DATA<2,n>
    Http request Header data - This is the data you want to include with this header name
  • POST.DATA<-1>
    This is the data you want to send to the web server. Each AM (Char(254)) will be converted to a CRLF.
    Http response returned by the web server. That values are between 100-500. Most successful request will return with a value of 200 or 201 as per the HTTP protocol.
    Header Names returned with the response data. This is provided by the web server, and may include important information.
    Value for the header data
  • RESP.DATA<n>
    This is the data returned by the web server based on the URL, HTTP.METHOD, and POST.DATA. Each CRLF will be converted into an AM mark (char(254))
    All other communication errors, parsing error, or anything not related to the HTTP protocol will be returned here. If there is no error, then this will return '' or '0'


CALL IS.HTTPCLIENT("GET","http://www.google.com","","",HTTP.STATUS,"",HTTP.RESP,ERROR)
  CRT "Error ": ERROR

UniBASIC Sockets vs UniBASIC CallHTTP

UniBASIC extension provide in at least UniVerse 10.x and UniData 7.x included both the Socket ability and the CallHTTP. The CallHTTP provided a more simplified calling structure, and there is another article that talks specifically about that. The main drawback to the CallHTTP was that it had a hardcoded restriction on the 'Authorization' header. Only Basic HTTP authorizations were allowed. At the time CallHTTP was added, that was all that was required.

With the addition of OAuth 1.0 and OAuth 2.0, this becomes a problem. Since UniBASIC also had support for OPENSOCKET() and OPENSECURESOCKET(), it easy to work around by writing the HTTP protocol themselves.

HTTP Protocol

Working with the HTTP Protocol is actually very simple. It is a text-only protocol which allows you to build everything you need in one large string, and then pass it to the socket.

You then need to read the data being returned and then parse out the headers from the data. This again is pretty easy, but keep in mind the response back may be a very large string… 2MB or 10 MB depending on the web service or what you are trying to download.

This subroutine does not try to optimize processing of Very Large strings and will trying to store all that data in memory. This can result in a Overflow Runaway issues or, in rare cases, a System Abort. If you know you need to handle Very Large Strings, then you might want to change the way read of the information is handled to write the Very Larges string as blocks into a temp file.

This program does not do that, but can be easily modified to do so.

License Notes:

This program is free software in the public domain; you can redistribute it and/or modify it in any way you wish. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Commercial support and warranties of this software and code can be purchased through International Spectrum.

This program is not the only means to do this, but is a starting point or working sample that can be extended.


# # #          # # #          # # #


Related Articles

  • IS.HTTPCLIENT - Using Universe and UniData HttpCall Extensions

    Company: International Spectrum Database: UniData, UniVerse

    Universe and Unidata have built in UniBASIC extensions that make the job of calling to a HTTP web server relatively easy. If you look into the UniVerse and/or UniData BASIC extension manual, you will see references to the CallHTTP functions that were added. These functions isolate a lot of the complexity of writing the HTTP protocols by hand, but they still require you to do some work. The subroutine included with this article removes that set of complexity by creating a single subroutine that you can call.


    Company: International Spectrum Database: D3, jBASE, mv*Base, OpenQM, UniData, UniVerse

    CURL is an open source tools and can be found on every version of Linux being distributed. CURL can be find as compiled binaries as well as compliable source code. Many software applications integrate CURL using the libcurl, but in this case we will be using the curl command line routine using the command-line switches, standard-in, and standard-out to transmit information between MultiValue BASIC and CURL.

  • IS.HTTPCLIENT - D3 9.1 and above

    Company: International Spectrum Database: D3

    D3 9.1 and above includes support for both normal sockets and SSL sockets. This provide this version of D3 the ability to access both Http:// and Https:// without requiring an external OS routine.

  • Auditing Database Changes with UniVerse Indexing Subroutines

    Company: Modern MultiValue, LLC Database: UniVerse

    UniVerse has file triggers which can be used to call a subroutine whenever a new record is added, changed, or deleted from a file so that the change to the database can be recorded in an audit trail for IT governance and compliance requirements. But full blown triggers come with a certain amount of performance overhead. For simple auditing, using indexing suboutines with a new system variable available at release 11.1 is a lighter weight alternative.

  • Email from U2 Hold Files as PDFs

    Database: UniVerse

    Printing is only one way to share reports. Felix provides code for re-inventing hold files as PDFs and as email.

Return to top