0

I am working on a procedure, in MS-Access VBA, to POST an XML text string to a web service and process the XML text string that is returned from the service.

The issue I am having is that the responseText property is always empty when it should contain a XML text string. No errors are returned and the .status = "OK".

I have tried the WinHttp.WinHttpRequest, MSXML2.XMLHTTP, and MSXML2.ServerXMLHTTP objects and consistently have the same issue.

Here is a code example:

Public Function Send() As Boolean
  Dim oXHR As MSXML2.XMLHTTP60
  Dim sURL, sCred As String
  Dim sRequest, sResult, sStatus, sHeader As String
  Dim bRtn As Boolean

  BuildReqXML
  sRequest = Me.RequestXML_String

  With orsValues
    sURL = .Fields("WebServiceURL").Value
    sCred = Base64Encode(Trim(.Fields("User").Value) & ":" &  Trim(.Fields("Password").Value))
  End With

  Set oXHR = New MSXML2.XMLHTTP60
  With oXHR

    .Open "POST", sURL, False
    .SetRequestHeader "Authorization", "Basic " & sCred & """"

    .SetRequestHeader "User-Agent", "Mozilla/4.0"
    .SetRequestHeader "Content-Type", "text/xml"

    .Send sRequest

    sStatus = .StatusText
    sResult = .ResponseText
    sHeader = .GetAllResponseHeaders

    If sResult <> "" Then
      If Contains(sResult, "<") Then ReadXML sResult, "Response"
      Debug.Print sResult
    Else
      Debug.Print sHeader
      Debug.Print sRequest
    End If
  End With

  Set oXHR = Nothing

End Function

I have verified that the web service is working correctly by building a similar call in a HTML document, sending the XML string, and receiving the response XML string.

Can someone please help me fix my issue?

PcDave69
  • 1
  • 1

1 Answers1

0

I found the problem, with help from Fiddler.

The line setting the authorization header

.SetRequestHeader "Authorization", "Basic " & sCred & """"

Was adding a (") to the header line. The corrected line is

.SetRequestHeader "Authorization", "Basic " & sCred 

Thank you for your help

PcDave69
  • 1
  • 1