title: Cookie authentication using MSXML2 in Excel VBA
body: <p>I'm trying to create an Excel macro to perform a search on a website and retrieve the results. I used the Chrome DevTools to visualize the requests the browser does and then replicate them in excel.
  There's no login, so the Authentication section is always empty, but when you first access the website it sends a GET request that returns a Set-Cookie response header, then you have to use this cookie in order to make any other request, but for some reason when you try to use it through excel or any other service that's not a browser, it returns you a "Session expired" error.
  I tried using Postman to reproduce every single request it makes, with every single header and parameters, but it only works if a browser session is open (Postman Chrome extension), if I use the Desktop App it won't work as well.
  Don't know if this can be the problem but the website uses Servlet 3.0 to process it's requests.</p>
  
  <p>I read on <a href="https://www.drupal.org/project/services/issues/1133084" rel="nofollow noreferrer">this post</a> in another forum that you can't set cookies manually when making a XMLHttpRequest (not sure if it's true though), so I wonder if there's some alternative to use this inside excel, or if I'm doing something wrong. The code I'm using can be resumed this:</p>
  
  <p>The first request, that returns you a cookie:</p>
  
  <pre><code>Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
  URL = "http://MY_URL/index.jsp"
  objHTTP.Open "GET", URL, False
  
  objHTTP.send
  
  MsgBox (objHTTP.getAllResponseHeaders)
  cookie = Split(objHTTP.getResponseHeader("Set-Cookie"), ";")(0)
  </code></pre>
  
  <p>Then I stored the cookie in the variable 'cookie', then passed it as a header in the search request:</p>
  
  <pre><code>URL = "http://MY_URL/SEARCH_SERVLET"
  objHTTP.Open "POST", URL, False
  objHTTP.setRequestHeader "Cookie", cookie
  
  objHTTP.send ("lifecycle=drawingnumberdata&amp;item=ITEM_PART_NUMBER&amp;revision=&amp;mode=&amp;includehistoricaldrawings=false")
  
  MsgBox (objHTTP.responseText)
  </code></pre>
  
  <p>I thought about creating a web application, to access this website and make the searches an then pass the results to excel. This way I won't need to authenticate through Excel VBA, but as it would cost me some effort, I decided to ask first if this is possible.</p>
  
  <p>This is my first post at StackOverflow, if I missed some information, or something is not clear please let me know.</p>