英文:
How can I get cookie/session information so that I can use it with an API?
问题
我正在尝试使用这个API:https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService
但是它基本上要求我已经有一个会话/cookie,所以我需要让我的Go
程序模拟一个连接并按照这个格式进行Steam
身份验证:https://github.com/SteamDatabase/SteamTracking/blob/master/API/ISteamUserAuth.json
但是我不太确定如何将所有这些组合在一起,以便让我的Go程序进行“登录”,以便我可以调用API的已登录部分。谢谢任何帮助,如果需要更多信息,请告诉我。
英文:
I'm trying to use this API:
https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService
But it basically requires me to have a session/cookies in place already so I need to basically make my Go
program simulate a connection and Authenticate
to steam following this format: https://github.com/SteamDatabase/SteamTracking/blob/master/API/ISteamUserAuth.json
But I'm not exactly sure how I can put this all together to get my Go program to login
so that I can make calls to the logged in portion of the API. Thanks for any help sorry if this isn't very clear, if needing more information just ask.
答案1
得分: 2
使用cookiejar
来记住cookies。
// 使用cookie jar创建一个客户端
client := &http.Client{Jar: cookiejar.New(nil)}
// 发送POST请求到认证URL
client.Post("...", "application/json", data)
// 使用同一个客户端发送请求
client.Get("...")
英文:
Use a cookiejar
to remember cookies.
// make a client with a cookie jar
client := &http.Client{Jar:cookiejar.New(nil)}
// post to the auth url
client.Post("...", "application/json", data)
// with the same client make your request
client.Get("...")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论