title: VBA setRequestHeader "Authorization" failing
body: <p>I am trying to connect to a Web Database with the following code, but it does not seem to work when automated in VBA. The login and password are fine as I can connect manually with them. </p>
  
  <p>is it possible that the Object: "WinHttp.WinHttpRequest.5.1" does not work with this sort of database connection? Or maybe am I missing a parameter in my Connect sub? Any help on this matter would be greatly appreciated.</p>
  
  <pre><code>Sub Connect()
  
  Dim oHttp As Object
  Set oHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
  Call oHttp.Open("GET", "http://qrdweb/mg/loan/loans.html?show=all", False)
  
  oHttp.setRequestHeader "Content-Type", "application/xml"
  oHttp.setRequestHeader "Accept", "application/xml"
  oHttp.setRequestHeader "Authorization", "Basic " + Base64Encode("login123" +  ":" + "pass123")
  
  
  Call oHttp.send
  
  Sheets("Sheet1").Cells(1, 1).Value = oHttp.getAllResponseHeaders
  Sheets("Sheet1").Cells(1, 2).Value = oHttp.ResponseText
  
  End Sub
  
  Private Function Base64Encode(sText)
  Dim oXML, oNode
  Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
  Set oNode = oXML.createElement("base64")
  oNode.DataType = "bin.base64"
  oNode.nodeTypedValue = StringToBinary(sText)
  
  
  Base64Encode = oNode.Text
  Set oNode = Nothing
  Set oXML = Nothing
  End Function
  
  Private Function StringToBinary(Text)
  Const adTypeText = 2
  Const adTypeBinary = 1
  
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  
  BinaryStream.Type = adTypeText
  BinaryStream.Charset = "us-ascii"
  BinaryStream.Open
  BinaryStream.WriteText Text
  
  'Change stream type To binary
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeBinary
  
  'Ignore first two bytes - sign of
  BinaryStream.Position = 0
  
  StringToBinary = BinaryStream.Read
  
  Set BinaryStream = Nothing
  End Function
  </code></pre>
  
  <p>The oHttp.getAllResponseHeaders displaying the getAllresponseHeaders outputs the following information:</p>
  
  <p>Cache-Control: must-revalidate,no-cache,no-store</p>
  
  <p>Connection: keep-alive</p>
  
  <p>Date: Fri, 24 Feb 2017 17:19:54 GMT</p>
  
  <p>Content-Length: 30633</p>
  
  <p>Content-Type: text/html;charset=ISO-8859-1</p>
  
  <p>Server: nginx/1.11.6</p>
  
  <p>WWW-Authenticate: Digest realm="QRDWEB-MNM", domain="", nonce="aB5DLmvuCfok9Zo112jo4S0evgOuXntE", algorithm=MD5, qop="auth", stale=true</p>
  
  <p>While the oHttp.ResponseText displaying the ResponseText outputs the following information:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/&gt;
          &lt;title&gt;Error 401 Server Error&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  </code></pre>
  
  <h2>Edit 1</h2>
  
  <p>When I comment out the 3 lines of code containing: oHttp.setRequestHeader, and changing the line: Set oHttp = CreateObject("WinHttp.WinHttpRequest.5.1") by Set oHttp = CreateObject("MSXML2.XMLHTTP"), a pop up appears for a login and password. If I fill in the information the following responses are different:</p>
  
  <p>The oHttp.getAllResponseHeaders displaying the getAllresponseHeaders outputs the following information:</p>
  
  <p>Server: nginx/1.11.6</p>
  
  <p>Date: Fri, 24 Feb 2017 18:19:02 GMT</p>
  
  <p>Transfer-Encoding: chunked</p>
  
  <p>Connection: keep-alive</p>
  
  <p>While the oHttp.ResponseText displaying the ResponseText outputs the following information:</p>
  
  <pre><code>&lt;html&gt;
  
      &lt;head&gt;
  
          &lt;title&gt;M&amp;M - Loan Viewer&lt;/title&gt;
  
          &lt;script language="javascript" type="text/javascript"&gt;
  
              function showTransactionComments(loanId, date, type, commentsTableWidth) {
  
      //alert(loanId + " " + date + " " + type + " " + commentsTableWidth);
      if (window.ActiveXObject) {
          return;
  </code></pre>
  
  <h2>Edit 2</h2>
  
  <p>I am now attempting to integrate Digest Authentication into VBA with the following sub and I get 2 possible outcomes: The first outcome is the same 401 error when using the wrong login info and the return is immediate. However, when I provide the proper login info, the operation times out... What could be causing that? </p>
  
  <pre><code>Sub digest()
      Dim http As New WinHttpRequest
      Dim strResponse As String
  
      Set http = New WinHttpRequest
  
      http.Open "GET", "http://qrdweb/mg/loan/loans.html?show=all", False
      http.SetCredentials "login123", "pass123", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
      http.send
  
      Sheets("Sheet1").Cells(1, 1).Value = http.getAllResponseHeaders
      Sheets("Sheet1").Cells(1, 2).Value = http.ResponseText
  
      http.Open "PROPFIND", "http://qrdweb/mg/loan/loans.html?show=all", False
      http.send
  
  End Sub
  </code></pre>