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'
This is the "Http://" or "Https://" want to request data from or send data to.
Http Request Header Name - This is the header name that the developer wants to included with the request to the server.
Http request Header data - This is the data you want to include with this header name
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
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'
IF (ERROR<1> GT 0) THEN
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.
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.
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.