Ashwin
Ashwin

Reputation: 247

POST request from Excel vba on ssl enabled url

I'm really tangled over here. I'm trying to make a authentication login call from my Excel, please find my code below.

Sub Authen()
Dim qTestServ As New MSXML2.XMLHTTP 

With qTestServ
    .Open "Post", "https://testURL.com/oauth/token", False
    .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .SetRequestHeader "Authorization", "Basic encodedvalue="
    .Send ("grant_type=value&username=userOne&password=testing123")
    msgbox(.ResponseText)

    If Not .Status = 200 Then
        MsgBox "UnAuthorized"
        Exit Sub
    End If

End With

Set qTestServ = Nothing
End sub

Please find the references added to my projects below. enter image description here

Please find error message i'm receiving below.

enter image description here

Many thanks in advance!!!

Upvotes: 2

Views: 3472

Answers (1)

Ashwin
Ashwin

Reputation: 247

Thanks for the suggestion Tim Williams.

I was using Dim qTestServ As New MSXML2.XMLHTTP to declare and changed that to Dim qTestServ As New MSXML2.ServerXMLHTTP

Please find the code below

Dim qTestServ As New MSXML2.ServerXMLHTTP

Sub Authen()
Dim qTestServ As New MSXML2.XMLHTTP 

With qTestServ
    .Open "Post", "https://testURL.com/oauth/token", False
    .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .SetRequestHeader "Authorization", "Basic encodedvalue="
    .Send ("grant_type=value&username=userOne&password=testing123")
    msgbox(.ResponseText)

    If Not .Status = 200 Then
        MsgBox "UnAuthorized"
        Exit Sub
    End If

End With

Set qTestServ = Nothing
End sub

Please refer to msxml6.dll: The download of the specified resource has failed.

Upvotes: 3

Related Questions