none
https & http2 requests with cookies support RRS feed

  • Question

  • For several years, I have been doing httprequests in both Access and Excel. I now need to include cookie(s) in some of my requests. And many sites are evolving to http2 and requiring use of https. I have no problems with https as long as no cookie(s) is required.

    My vba code for this is below. If no cookie is required, this code works. When I add the setRequestheader for the cookie, I can not get it to work. Web searches indicate a Microsoft stated bug (kb290899 from 2002). The kb indicate to do the cookie twice as I did in the commented line of code below. This does not work. I am able to re-code in Python and have this python code working.

    Can someone suggest how to do this in vba or is there vba alternatives(s)?

    Thank you.

    Sub http2()
    Dim urlAs String
    Dim http As New MSXML2.XMLHTTP60
    url = "https://mycookiesite.com"
    http.Open "GET", url, False
    http.setRequestHeader "Cookie", "B='5jjfk45cim4db&b=3&s=9j;"
    ' http.setRequestHeader "Cookie", "B=5jjfk45cim4db&b=3&s=9j;"
    http.Send
    MsgBox (http.responseText)
    End Sub


    Jim Gunn

    Wednesday, May 31, 2017 3:28 PM

Answers

  • Hi JimGDal,

    I view the document mentioned by you.

    I want to confirm with you that did you try to create an ASP page with code below?

    <%
     Response.Write "Cookie: " & CStr(Request.ServerVariables("HTTP_COOKIE"))
    %>

    did you execute line below on command prompt?

    wscript c:\cookie.vbs

    Reference:

    BUG: XMLHTTP Fails to Send Cookies from a Client

    you had asked for any other way to work around this issue.

    I find one thread in which I find that other community member had suggested to use ServerXMLHTTP.

    Reference:

    XMLHTTP Fails to Send Cookies from a Client -- issue seems not fixed

    you can try to refer it and check whether it solves your issue or not.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JimGDal Thursday, June 1, 2017 11:48 PM
    Thursday, June 1, 2017 6:12 AM
    Moderator

All replies

  • Hi JimGDal,

    I view the document mentioned by you.

    I want to confirm with you that did you try to create an ASP page with code below?

    <%
     Response.Write "Cookie: " & CStr(Request.ServerVariables("HTTP_COOKIE"))
    %>

    did you execute line below on command prompt?

    wscript c:\cookie.vbs

    Reference:

    BUG: XMLHTTP Fails to Send Cookies from a Client

    you had asked for any other way to work around this issue.

    I find one thread in which I find that other community member had suggested to use ServerXMLHTTP.

    Reference:

    XMLHTTP Fails to Send Cookies from a Client -- issue seems not fixed

    you can try to refer it and check whether it solves your issue or not.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JimGDal Thursday, June 1, 2017 11:48 PM
    Thursday, June 1, 2017 6:12 AM
    Moderator
  • Thank you for your response.

    I did some more work today and seem to have it working. I am able to download content requiring a cookie.

    I attempting a client request with a cookie already established. And it is not my web site with access to ASP. So I did not try to "Create an ASP page with code" as you suggested.

    My code is exactly as above (with appropriate url) using:

    Dim http As MSXML2.XMLHTTP60: Set http = New MSXML2.ServerXMLHTTP60"

    And it requires only 1 setRequestHeader line.

    I am very interest in increasing my understanding of http/2 and https. It seems this is where web development is going. So any references will be appreciated. My app would be more efficient if I can learn to make multiple http/2 async requests in one TCP connection?

    Thank again.

    Regards,

    Jim


    Jim Gunn

    Thursday, June 1, 2017 11:48 PM