How can I get cookie/session information so that I can use it with an API?

huangapple go评论87阅读模式
英文:

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("...")

huangapple
  • 本文由 发表于 2015年8月22日 10:05:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/32151546.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定