• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Desired cookie value not returned in response

arpit singh

New Member
I have written a VBA code to get-- option-chain-indices?symbol=nifty file & type=json data through web connection.
I want to get both the request & response cookies from the website . But the issue is my code is returning some other file cookie value not from this file-option-chain-indices?symbol=nifty.......My code is as below-

>>> as You have already noticed <<<
>>> use code - tags <<<

Code:
Sub GetCookie3()

    Dim web, strUrl, strCookie, strCookie1, strUrlrefer
    On Error Resume Next
   
    strUrl = "https://www.nseindia.com/api/option-chain-indices?symbol=" & WorksheetFunction.EncodeURL("NIFTY")
    strUrlrefer = "https://www.nseindia.com/option-chain?symbolCode=-10006&symbol=NIFTY&symbol=NIFTY&instrument=-&date=-&segmentLink=17&symbolCount=2&segmentLink=17"
   
    Set web = CreateObject("MSXML2.ServerXMLHTTP")

    web.Open "GET", strUrl, False
   
    web.SetRequestHeader "Host", "www.nseindia.com"
    web.SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:88.0) Gecko/20100101 Firefox/88.0)"
    web.SetRequestHeader "Accept", "*/*"
    web.SetRequestHeader "Connection", "keep-alive"
    web.SetRequestHeader "Accept-Language", "en-US,en;q=0.5"
    web.SetRequestHeader "Accept-Encoding", "gzip, deflate, br"
    web.SetRequestHeader "Referer", strUrlrefer
    web.SetRequestHeader "Connection", "keep-alive"
   
    web.Send
   
   
    If web.Status <> 200 Then Debug.Print web.Status & " website status: " & web.StatusText
    Debug.Print web.Status & "************ website status:********** " & web.StatusText
   
      
       strCookie = web.GetAllResponseHeaders
        strCookie = Split(strCookie, vbCrLf)
        strCookie1 = strCookie(5) & vbCrLf & strCookie(6)
        Debug.Print "___COOKIE_____" & strCookie(10)
        'i = 0
        'For Each Item In strCookie
        'Debug.Print "At position: " & i & "__Is_" & strCookie(i)
        'i = i + 1
        'Next
       
End Sub
 
Last edited by a moderator:
Top