Page 1 of 1

How to send an HTTP POST request from a Basic macro

Posted: Sun Aug 04, 2024 2:26 pm
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