Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How make POST HTTP request with OAuth2OOo ? #13

Closed
alalexkr opened this issue Oct 24, 2023 · 6 comments
Closed

How make POST HTTP request with OAuth2OOo ? #13

alalexkr opened this issue Oct 24, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@alalexkr
Copy link

  1. How make this POST HTTP request with OAuth2OOo (LibreOffice BASIC):
    POST / HTTP/1.1
    Host : http://foo.com/
    Content-Type : application/x-www-form-urlencoded
    Content-Length : 13

say=Hi&to=Mom

  1. Please give an example of filling a Object Parameters - how fill Data(integer(0 to -1)) ?

  2. Where we can see the description of methods and properties of Object OAuth2OOo ?

@prrvchr
Copy link
Owner

prrvchr commented Oct 26, 2023

In fact POST requests in application/x-www-form-urlencoded encoding were not supported...
I have just updated OAuth2OOo to version 1.1.2 which now allows such requests...

There are 3 macros in Basic accessible in: Tools -> Macros -> Run Macros... -> My Macros -> OAuth2OOo

  • ChatGPTRequest
  • HTTPGetRequest
  • HTTPPostRequest

Be careful, these macros will not work if no document is open (I don't know why?)...
You can play with these macros in: Tools -> Macros -> Edit macros...

For more information see: What has been done for version 1.1.2

@prrvchr prrvchr added the enhancement New feature or request label Oct 26, 2023
@alalexkr
Copy link
Author

alalexkr commented Oct 27, 2023

Or you can use OAuth2OOo (LibreOffice BASIC) to send the following request:

POST / HTTP/1.1
Host : http://foo.com/
Content-Type: text/xml; charset=utf-8

<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""; xmlns:xsd=""http://www.w3.org/2001/XMLSchema""; xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">;
soap:Body
<SendMessage xmlns=""http://mcommunicator.ru/M2M"">;



</soap:Body>
</soap:Envelope>

this is an imitation of SOAP requests

Thanks!

@alalexkr
Copy link
Author

and when calling
oauth2 = CreateUnoService("io.github.prrvchr.OAuth2OOo.OAuth2Service")

the error appears now

runtimeerror Basic.
Type: com.sun.star.lang.DisposedException
Message: Binary URP bridge already disposed at /opt/astra/libreoffice/libreoffice-7.5.2~rc1/binaryurp/source/bridge.cxx:1048.

@prrvchr
Copy link
Owner

prrvchr commented Oct 27, 2023

Or you can use OAuth2OOo (LibreOffice BASIC) to send the following request:

Sub Main

    Rem First we need to create the UNO OAuth2Service
    oauth2 = CreateUnoService("io.github.prrvchr.OAuth2OOo.OAuth2Service")

    Rem To execute an HTTP request we first need a HTTP Request parameter
    parameter = oauth2.getRequestParameter("httpbin")

    Rem Default Requests method is GET and must be changed
    parameter.Method = "POST"

    parameter.Url = "https://httpbin.org/post"

    Rem Default authentication is OAuth2 but can be disabled with:
    parameter.NoAuth = true

    Rem We construct the Soap Content (as text):
    sSoap = "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
            "<soap:Body>" & _
            "<SendMessage xmlns=""http://mcommunicator.ru/M2M"" />" & _
            "</soap:Body>" & _
            "</soap:Envelope>"

    Rem As we use parameter.Text we need to set the HTTP header Content-Type
    parameter.setHeader("Content-Type", "text/xml; charset=utf-8")

    Rem We set the Text property of the parameter:
    parameter.Text = sSoap

    Rem To obtain the HTTP response we use the execute() method
    Rem of the OAuth2Service service with the HTTP parameter as argument
    response = oauth2.execute(parameter)

    if response.Ok then
        sText = "Your POST data is:" & Chr(13) & response.getJson().getString("data")
    else
        sText = response.Text
    endif

    Rem When it is finished we have to close the HTTP response
    response.close()

    Msgbox sText

End Sub

runtimeerror Basic.
Type: com.sun.star.lang.DisposedException
Message: Binary URP bridge already disposed at /opt/astra/libreoffice/libreoffice-7.5.2~rc1/binaryurp/source...

I think you need to restart LibreOffice

Edit:
Be careful to always edit Macros in Basic with the LibreOffice editor (ie: Tools -> Macros - Edit Macros...)

@alalexkr
Copy link
Author

Very cool!)
Everything is working !
Thank you!

@prrvchr
Copy link
Owner

prrvchr commented Oct 27, 2023

You are welcome, enjoy...
I close this issue, you are free to open a new one if necessary.

@prrvchr prrvchr closed this as completed Oct 27, 2023
@prrvchr prrvchr pinned this issue Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants