title: VBA XMLHTTP query returning 403 error
body: <p>I am currently attempting to retrieve a json string using XMLHTTP in VBA from the website url detailed below. Loading the first url creates a session, which I retrieve from the HTML body. A call to the second url, using the session ID &amp; other request headers visible from develop tools results in a 403 error. I have tried multiple combinations of headers with no effect. For deployment purposes a VBA solution is required. Any input/ideas would be much appreciated.</p>
  
  <pre><code>Sub test()
  
  Dim wbk_TB As Workbook
  Dim var_array As Variant
  
  Dim url As String
  Dim data As Variant
  Dim XMLHTTP As MSXML2.XMLHTTP
  Dim hdoc As MSHTML.HTMLDocument
  
  Set wbk_TB = ThisWorkbook
  Set XMLHTTP = New MSXML2.XMLHTTP
  url = "http://www.eex-transparency.com/homepage/power/germany/production/availability/non-usability"
  XMLHTTP.Open "GET", url, False
  
  XMLHTTP.setRequestHeader "Accept", "application/json, text/plain, */*"
  XMLHTTP.send
  
  data = XMLHTTP.responseText
  
  Dim HTMLdoc As MSHTML.HTMLDocument
  Set HTMLdoc = New MSHTML.HTMLDocument
  HTMLdoc.body.innerHTML = XMLHTTP.responseText
  
  Name = "session=" &amp; HTMLdoc.getElementsByName("session").Item(0).Value
  
  url = "http://www.eex-transparency.com/dsp/tem-12?country=de&amp;limit=50&amp;offset=50"
  
  XMLHTTP.Open "GET", url, True
  XMLHTTP.setRequestHeader "Host", "www.eex-transparency.com"
  XMLHTTP.setRequestHeader "Proxy-Connection", "keep-alive"
  XMLHTTP.setRequestHeader "Accept", "application/json, text/plain, */*"
  XMLHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36"
  XMLHTTP.setRequestHeader "Referer", "http://www.eex-transparency.com/homepage/power/germany/production/availability/non-usability"
  XMLHTTP.setRequestHeader "Accept-Encoding", "gzip,deflate,sdch"
  XMLHTTP.setRequestHeader "Cache-Control", "max-age=0"
  XMLHTTP.setRequestHeader "Accept-Language", "en-US,en;q=0.8"
  XMLHTTP.setRequestHeader "Cookie", Name
  
  XMLHTTP.send
  
  While XMLHTTP.readyState &lt;&gt; 4
      DoEvents
  Wend
  
  data = XMLHTTP.responseText
  
  End Sub
  </code></pre>