How to retrieve cookies in PowerShell?

Welcome Forums General PowerShell Q&A How to retrieve cookies in PowerShell?

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
8 months, 3 weeks ago.

  • Author
    Posts
  • #94381

    Participant
    Points: 0
    Rank: Member

    I would like to know on how to retrieve cookies on sample 2.

    Sample 1

    $URL = Invoke-WebRequest http://www.google.com
    $URL.BaseResponse.Cookies

    Sample 2

    $URL = "http://www.google.com"
    (Invoke-WebRequest -Uri $URL -SessionVariable Y -UseBasicParsing).Content | Out-File -FilePath C:\TEMP.txt
    $URL.baseresponse.cookies, which show nothing

    Does anyone have any suggestions?
    Thanks in advance for any suggestions

  • #94384

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    $y would include session state information, including cookies. Probably encoded.

    Also, if no cookies were passed, there won't be any.

  • #94386

    Participant
    Points: 0
    Rank: Member

    On sample 1, cookies is created through Invoke-WebRequest.
    On sample 2, cookies should also be created, but when I input following commands, which return nothing.
    $URL.BaseResponse.Cookies
    $Y.BaseResponse.Cookies
    I would like to know any difference on how cookies are handled on sample 2 comparing with sample 1 and how to retrieve cookies under this situation for sample 2.
    Do you have any suggestions?
    Thank you very much for any suggestions (^v^)

  • #94497

    Participant
    Points: 0
    Rank: Member

    In sample 2 $url is just the string containing the URL you're accessing so will have no knowledge of cookies

    $Y.cookis contains some information but not sure how to drill down into the actual cookies

  • #94500

    Participant
    Points: 0
    Rank: Member

    On web-server side, I would like to know on how server looks at both following requests.
    On the other words, do server make a connection log (successful) for both following requests?
    Cookies is found for sample 1, but cookies is unknown for sample 2.

    1) $URL = Invoke-WebRequest http://www.google.com
    2) (Invoke-WebRequest -Uri $URL -SessionVariable Y -UseBasicParsing).Content | Out-File -FilePath C:\TEMP.txt

    Do you have any suggestions on any difference on web connection from server side?
    Thanks, to everyone very much for any suggestions (^v^)

The topic ‘How to retrieve cookies in PowerShell?’ is closed to new replies.