Joh*_*ith 5 cookies http-authentication go web
我希望我的 Go 应用程序通过网站进行身份验证,然后使用收到的 cookie 访问安全位置。以下卷曲示例准确地说明了我想要做的事情:
通过网站进行身份验证x-www-form-urlencoded并保存 cookie。数据自动进行 urlencode 编码:
curl 'https://www.example.com/login' \
--cookie-jar cookies.txt \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'user=USER NAME&pass=PASS'
Run Code Online (Sandbox Code Playgroud)
现在身份验证 cookie 已保存cookies.txt,我只需发送它即可访问需要登录的页面:
curl 'https://www.example.com/profile' \
--cookie cookies.txt
Run Code Online (Sandbox Code Playgroud)
我不想将 cookie 存储在我的应用程序的磁盘上,而只想存储在内存中,以便我可以在需要时使用它。
有谁有一个例子来说明如何在 Go 中实现这一点?