cookie和cookiejar有什么区别? [英] What is the difference between cookie and cookiejar?

查看:2757
本文介绍了cookie和cookiejar有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我遇到了cookiejar这个术语(包 net / http / cookiejar )。我试图收集一些关于它的信息,但没有什么可以理解。我知道 cookie 是服务器发送给客户端的键/值对,例如: Set-Cookie:foo = 10 然后每个后续请求浏览器将这些cookie发送回服务器,例如: Cookie:foo = 10

Today I faced with the term "cookiejar" (package net/http/cookiejar). I tried to gather some information regarding it, but got nothing intelligible. I know that cookie is key/value pairs that server sends to a client, eg: Set-Cookie: foo=10, browser store it locally and then each subsequent request browser will send these cookies back to the server, eg: Cookie: foo=10.

好的,但 cookiejar

推荐答案

正如您在问题中所述,Cookie是由浏览器(HTTP客户端)管理的,

As you described in your question, cookies are managed by browsers (HTTP clients) and they allow to store information on the clients' computers which are sent automatically by the browser on subsequent requests.

如果您的应用程序充当客户端(您连接到远程HTTP服务器使用 net / http 包),则有没有可以处理/管理cookie的浏览器。这意味着存储/记住以 Set-Cookie:形式到达的cookie,并将它们附加到同一主机/域的后续传出请求。

If your application acts as a client (you connect to remote HTTP servers using the net/http package), then there is no browser which would handle / manage the cookies. By this I mean storing/remembering cookies that arrive as Set-Cookie: response headers, and attaching them to subsequent outgoing requests being made to the same host/domain. Also cookies have expiration date which you would also have to check before deciding to include them in outgoing requests.

http.Client 允许您设置 http.CookieJar ,如果这样做,您将有自动Cookie管理,否则不会存在或你必须自己做。这使您能够使用服务器将作为同一会话的一部分看到的 net / http 包执行多个请求,就像它们是由真实的浏览器所做的一样HTTP会话(会话ID)使用Cookie维护。

The http.Client type however allows you to set a value of type http.CookieJar, and if you do so, you will have automatic cookie management which otherwise would not exist or you would have to do it yourself. This enables you to do multiple requests with the net/http package that the server will see as part of the same session just as if they were made by a real browser, as often HTTP sessions (the session ids) are maintained using cookies.

net / http / cookiejar 是一个CookieJar实现,您可以立即使用。请注意,此实现仅在内存中,这意味着如果您重新启动应用程序,Cookie将会丢失。

The package net/http/cookiejar is a CookieJar implementation which you can use out of the box. Note that this implementation is in-memory only which means if you restart your application, the cookies will be lost.

基本上, HTTP Cookie 是从网站发送的一小段数据,存储在用户的

So basically an HTTP cookie is a small piece of data sent from a website and stored in a user's web browser while the user is browsing that website.

Cookiejar 是一个 Go界面 / cookiejar />该接口的实现。

Cookiejar is a Go interface of a simple cookie manager (to manage cookies from HTTP request and response headers) and an implementation of that interface.

这篇关于cookie和cookiejar有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆