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

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

问题描述

今天我遇到了cookiejar"这个词.(包 net/http/cookiejar).我试图收集一些关于它的信息,但没有得到任何可理解的信息.我知道 cookie 是服务器发送给客户端的键/值对,例如:Set-Cookie: foo=10,浏览器将其存储在本地,然后每个后续请求浏览器将这些 cookie 发送回服务器,例如:Cookie: foo=10.

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

好的,但是 cookiejar 怎么样?它是什么以及它是什么样子的?

Ok, but what about cookiejar? What is it and how does it look like?

推荐答案

正如您在问题中所描述的,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.

如果您的应用程序充当客户端(您使用 net/http 连接到远程 HTTP 服务器 包),则没有浏览器可以处理/管理 cookie.我的意思是存储/记住作为 Set-Cookie: 响应标头到达的 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 是一个简单的 cookie 管理器的 Go 界面(用于管理来自 HTTP 请求和响应标头的 cookie)和该接口的实现.

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天全站免登陆