jeudi 6 avril 2017

Receiving and sending cookies with Go client?

I want my Go application to authenticate with a website and then use the received cookie to access secure locations. The following curl examples illustrates exactly what I'm trying to do:

Authenticate with website via x-www-form-urlencoded and save cookie. Data is urlencoded automatically:

curl 'http://ift.tt/1o6ieYS' \
    --cookie-jar cookies.txt \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data 'user=USER NAME&pass=PASS'

Now authentication cookie is saved in cookies.txt and I just send that to access a page that requires login:

curl 'http://ift.tt/1O6gsY6' \
    --cookie cookies.txt

I don't want to store the cookie on disk in my application, only in memory so I can use it when required.

Does anyone have an example of how this can be achieved in Go?




Aucun commentaire:

Enregistrer un commentaire