'How to use ServerXMLHTTP60 and a client SSL certificate in Excel using VBA?

I cannot get it to work in VBA - Excel. I use the same header and XML-body in Postman - fine! Good response. I need to use a client certificate to identify myself, but I cannot get it done in VBA. The code needs to post some data (the XMLPostMessage) and then it receives some data from the server (a XML message as well).

The response I get from the server is a message in XML that has something to do with "Unidentified user". So, I do have communication, but it is not recognised as 'from a trusted party'. But using this certificate in Postman does give a good response.

== My VBA code: ==

Public Sub server()
Dim O As New ServerXMLHTTP60
Dim xmlDoc As New MSXML2.DOMDocument60
Dim XMLPostMessage As String

XMLPostMessage = "<WEB-UAS-AANVR>" & _
            "<ALG-GEG>" & _
                "<PROC-IDENT>3637</PROC-IDENT>" & _
                "<PROC-FUNC>1</PROC-FUNC>" & _
                "<INFO-GEBR>DITISEENTEST</INFO-GEBR>" & _
            "</ALG-GEG>" & _
            "<WEB-UAS-GEG>" & _
            "<UAS-VRR-EXAMEN-GEG>" & _
                    "<UAS-VRR-EX-INST></UAS-VRR-EX-INST>" & _
                    "<UAS-VRR-EX-SRT>A2</UAS-VRR-EX-SRT>" & _
                    "<UAS-VRR-EX-DAT>20211210</UAS-VRR-EX-DAT>" & _
                    "<GEB-DAT-UAS-VRR>19840726</GEB-DAT-UAS-VRR>" & _
                    "<UAS-VRR-EX-REF>#12345</UAS-VRR-EX-REF>" & _
                "</UAS-VRR-EXAMEN-GEG>" & _
            "</WEB-UAS-GEG>" & _
        "</WEB-UAS-AANVR>"

With O
    .Open "POST", "https://<the serverpath goes here>", False
    .setRequestHeader "Content-type", "application/xml"
    .setRequestHeader "Content-type", "text/xml"
    .setRequestHeader "Charset", "UTF-8"
    .setOption 3, "<The Friendly Name of the certificate goes here>"
'    .setOption 3, "CURRENT_USER\My\<The Friendly Name of the certificate goes here>"
    
    .send XMLPostMessage
    xmlDoc.LoadXML (O.responseXML.XML)
    Debug.Print xmlDoc.XML
    
    If Not .Status = 200 Then
        MsgBox "UnAuthorized. Message: " & .Status & " - " & .statusText
        Exit Sub
    End If
        
End With

Set O = Nothing

End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source