Excel VBA Msxml2.XMLHTTP.6.0 vs Msxml2.ServerXMLHTTP.6.0
<p>I am a self-taught, amateur programmer, and I am new to this forum. Please bear with me.</p>

<p>About two years ago, I wrote a simple Excel vba program to login in to a website and grab a customer statement in the form of a .csv file. My program utilizes GET and POST requests. This program worked perfectly (for my needs) until about three weeks ago, when it unfortunately broke on me. The program could not get through the initial GET request. Specifically, it would break on the getReq.send line.</p>

<p>I came across this post:
<a href="https://stackoverflow.com/questions/35906564/login-into-website-using-msxml2-xmlhttp-instead-of-internetexplorer-application">Login into website using MSXML2.XMLHTTP instead of InternetExplorer.Application with VBA</a></p>

<p>Here, I learned that you can use "Msxml2.XMLHTTP.6.0" instead of "Msxml2.ServerXMLHTTP.6.0". I modified my code accordingly, eliminating the need to parse cookies after the Get request, and it worked! But I have no idea. Even though I got it to work, I do not feel like I have learned much in the process.</p>

<p>Some information to note:</p>

<ul>
<li>My original program broke on my work computer (WindowsXP).</li>
<li>Figuring that it may be an XP issue, and in the market for a new machine anyway, I updated to a new computer running Windows7. The program still did not work, though I received a different error message.</li>
<li>I ran my code on a Windows10 computer and it worked fine.</li>
<li>I use identical code to connect to various other websites and it works fine, regardless of what operating system.</li>
</ul>

<p>So, my specific questions:</p>

<ol>
<li>Why might the code work with Msxml2.XMLHTTP.6.0 but not Msxml2.ServerXMLHTTP.6.0?</li>
<li>And why might the code have broken in the first place?</li>
<li>Why would the code work on one particular website, but no another?</li>
</ol>

<p>Any insight would be greatly appreciated. I have attached my code (with login info X'd out).</p>

<pre><code>Sub RCGInquiry()

    Dim postReq, getReq, cookies
    Dim p0 As Integer, p1 As Integer, temp As String
    Dim result As String, respHead As String

    Set getReq = CreateObject("Msxml2.ServerXMLHTTP.6.0")
    'Set getReq = CreateObject("Msxml2.XMLHTTP.6.0")

    ' Visit homepage so we can find the cookies
    getReq.Open "GET", "https://www.rcginquiry.com/sfs/Entry", False
    getReq.send

    respHead = getReq.getAllResponseHeaders

     Debug.Print respHead

    ' Need to parse the cookie from Respone Headers
    cookies = ""
    p0 = 1
    Do While InStr(p0, respHead, "Set-Cookie:") &gt; 0
        p0 = InStr(p0, respHead, "Set-Cookie:") + 11
        p1 = InStr(p0, respHead, Chr(10))
        temp = Trim(Mid(respHead, p0, p1 - p0))
        cookies = cookies &amp; temp &amp; "; "
    Loop
    cookies = Left(cookies, Len(cookies) - 2)

    ' Debug.Print cookies

    ' Login
    Set postReq = CreateObject("Msxml2.ServerXMLHTTP.6.0")
    'Set postReq = CreateObject("Msxml2.XMLHTTP.6.0")
    postReq.Open "POST", "https://www.rcginquiry.com/sfs/Entry", False
    postReq.setRequestHeader "Cookie", cookies
    postReq.setRequestHeader "Content-type", "application/x-www-form-urlencoded" 'send appropriate Headers
    postReq.send "Usrid=XXXX&amp;Psswd=XXXX" ' send login info

    '-------------------------------------------------------------------------------

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim FSO As Object
    Dim myFile As Object
    Dim path As String
    Dim y As Integer

    curDate = Format(Date, "mm_dd_yy")

    ' Download CSV
    postReq.Open "POST", "https://www.rcginquiry.com/sfs/Downloads/tmp.csv?filetype=POS&amp;format=MFA20&amp;heading=true&amp;allaccts=true&amp;junk=tmp.csv", False
    postReq.setRequestHeader "Cookie", cookies 'must resend cookies so it knows i am logged in
    postReq.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
    postReq.send "filetype=POS&amp;format=MFA20&amp;heading=true&amp;allaccts=true&amp;junk=temp.csv" 'url query parameters

    ' Writes responseText to a .csv file
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set myFile = FSO.createtextfile("C:\Users\Adam\Desktop\POSITION\" &amp; curDate &amp; ".csv", True)
    myFile.write (postReq.responseText)
    myFile.Close

    Set FSO = Nothing
    Set myFile = Nothing

End Sub
</code></pre>