How to send an HTTP POST request from a Basic macro

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
Cormic
Posts: 10
Joined: Tue Jul 16, 2024 1:50 pm

How to send an HTTP POST request from a Basic macro

Post by Cormic »

Hello,
This post presents a solution to execute a HTTP POST request in Basic avoiding any external library.

It uses UNO Universal Content Broker, and works under Windows and Linux (I didn't test Mac OS)

The code is in the Calc attached file, in the module HTTPmodule.
The example URL (line 4 : POST_URL = "http://mco.s2hnh.org/") is functional (but not forever :-)). I will probably need to reuse this URL in the future, so you will have to use another server)

Clicking on the sheet button "Tester l'envoi POST" will run the subroutine Main, which will display the POST answer.
Due to a former bug in UCB, Linux LibreOffice may send PUT request instead of POST. This bug has been corrected (in LibreOffice version 6 or 7, I am not sure). The POST answer from http://mco.s2hnh.org/ will show the parameters received (should be in MIME format application/x-www-form-urlencoded) and indicate if it was a PUT or a POST answer.

Hope it will be usefuL
Sincerely
Attachments
Test_HTTP_POST.ods
(13.01 KiB) Downloaded 237 times
LibreOffice 7.5.12 Windows 10
Post Reply