Domino on Linux/Unix, Troubleshooting, Best Practices, Tips and more ...

    Domino V10 - HTTP Requests and REST Services from Lotus Script

    Daniel Nashed  11 October 2018 00:55:16

    One of the long missed features in Lotus Script is to work with HTTP requests.
    Since Notes/Domino V10 you can now use HTTP requests directly from Lotus Script -- For example to query data from a website or from a REST service.

    In the beta I played around with it already. I was specially interested in authentication and HTTPS.

    HTTPS now works and authentication can be implemented on your own. The a bit tricky part is the Base64 routine that you need for the authorization header. But there is a way to leverage the MIME classes for that.

    So the following example helps you to get started. It builds the authentication header and also uses HTTPs to request a website.
    Tip: Depending on the request you might run into issues with too many redirects which the function does not follow automatically. So you have to increase the limit as shown in the example.

    For HTTPS the certificate needs to be verified. I have tested with my Let's Encrypt Certificated and it worked well.

    Another tip: If you run into issues with certificates or other parts of the NotesHTTPRequest, there is a debug notes.ini setting Debug_NotesHTTPRequest=1.

    I have tested the following example with the Notes V10 GA client.
    The Designer help has some additional information also for the other functions of that class.

    Enjoy

    -- Daniel


    Option Declare

    Sub Initialize
            Dim Session As New NotesSession        
            Dim ret As String
            Dim URL As String
            Dim headers As Variant
            Dim user As String
            Dim password As String
            Dim webRequest As NotesHTTPRequest
            Set webRequest = session.createhttprequest()

            user = "john@acme.com"
            password = "mypassword"
            webRequest.maxredirects5
            URL = "https://www.acme.com"
           
            Call webRequest.Setheaderfield("Authorization", "Basic " + EncodeBase64 (user + ":" + password))
           
            ret  = webrequest.Get(URL)
           
            headers = webRequest.GetResponseHeaders()
           
            ForAll h In headers
                    MessageBox h
            End ForAll
           
            MessageBox ret
    End Sub

    Function EncodeBase64 (StrIn As String) As String
            Dim session As New NotesSession
            Dim stream As NotesStream
            Dim db As NotesDatabase
            Dim doc As NotesDocument
            Dim body As NotesMIMEEntity
     

            Set stream = session.CreateStream
            Call stream.WriteText (StrIn)
           
            Set db = session.CurrentDatabase
            Set doc = db.CreateDocument
            Set body  = doc.CreateMIMEEntity
           
            Call body.SetContentFromText (stream, "", ENC_NONE)
            Call body.EncodeContent (ENC_BASE64)
           
            EncodeBase64 = body.ContentAsText
           
            Call stream.Close
            Set doc = Nothing
    End Function

    Archives


    • [IBM Lotus Domino]
    • [Domino on Linux]
    • [Nash!Com]
    • [Daniel Nashed]