Cookies Without Chocolate Chips

In the HTTP sense, a cookie is a name with an associated value. A server sends the name and value to the client, and expects it to get sent back on every subsequent request to the server that matches the particular conditions set. The conditions include that the domain name and path match and that the cookie hasn't become too old.
在Http中,cookie由name和value组成。
服务器发送name和value到客户端,并希望客户端每次发送子请求时附带上这些信息。
cookie包括 域名、路径、是否过期。

In real-world cases, servers send new cookies to replace existing ones to update them. Server use cookies to "track" users and to keep "sessions".
实际上,服务器发送新的cookie新到替换旧的信息。
服务器通过cookie追踪用户和保持session。

Cookies are sent from server to clients with the header Set-Cookie: and they're sent from clients to servers with the Cookie: header.
服务器发送cookie到客户端的时候,会发送http头:Set-Cookie
客户端发送cookie信息到服务器的时候,会发送Http头:

To just send whatever cookie you want to a server, you can use CURLOPT_COOKIE to set a cookie string like this:
可以通过设置CURLOPT_COOKIE属性,来发送cookie信息:

curl_easy_setopt(easyhandle, CURLOPT_COOKIE, "name1=var1; name2=var2;");

In many cases, that is not enough. You might want to dynamically save whatever cookies the remote server passes to you, and make sure those cookies are then used accordingly on later requests.
在大多数情况下,这无法满足需求。
你可以需要保存远程发送到本地的cookie信息,
并且在接下来的请求中附带cookie信息

One way to do this, is to save all headers you receive in a plain file and when you make a request, you tell libcurl to read the previous headers to figure out which cookies to use. Set the header file to read cookies from with CURLOPT_COOKIEFILE.
另外一种方法是,保存所有的收到的header到一个文件中,当需要发送请求时,让libcurl读取该文件,取出对应的cookie信息。
使用CURLOPT_COOKIEFILE设置libcurl读取的cookie的文件。

The CURLOPT_COOKIEFILE option also automatically enables the cookie parser in libcurl. Until the cookie parser is enabled, libcurl will not parse or understand incoming cookies and they will just be ignored. However, when the parser is enabled the cookies will be understood and the cookies will be kept in memory and used properly in subsequent requests when the same handle is used. Many times this is enough, and you may not have to save the cookies to disk at all. Note that the file you specify to ICURLOPT_COOKIEFILE(3) doesn't have to exist to enable the parser, so a common way to just enable the parser and not read any cookies is to use the name of a file you know doesn't exist.
并且CURLOPT_COOKIEFILE选项会使libcurl自动分析cookie。
除非cookie解析器被激活,否则libcurl不会分析cookie信息,而是全部忽略。
一旦cookie解析器被激活,cookie信息则会自动被保存在内存中,并且自动会在接下来对应的请求中使用
你完全可以不去保存cookie信息到磁盘中
需要注意,CURLOPT_COOKIEFILE(3)所指定的文件不一定要存在才能激活cookie分析功能,
所以一个激活cookie分析器常用的方法就是设置一个不存在的文件。

If you would rather use existing cookies that you've previously received with your Netscape or Mozilla browsers, you can make libcurl use that cookie file as input. The CURLOPT_COOKIEFILE is used for that too, as libcurl will automatically find out what kind of file it is and act accordingly.
你可以让libcurl使用一个之前用Netscape或者浏览器获取的cookie文件
也是用过CURLOPT_COOKIEFILE设置。

Perhaps the most advanced cookie operation libcurl offers, is saving the entire internal cookie state back into a Netscape/Mozilla formatted cookie file. We call that the cookie-jar. When you set a file name with CURLOPT_COOKIEJAR, that file name will be created and all received cookies will be stored in it when curl_easy_cleanup is called. This enables cookies to get passed on properly between multiple handles without any information getting lost.
也许libcurl在cookie方面提供最大的扩展是:保存整个内部的cookie信息到Netscape/Mozilla的格式。
我们把他称为cookie-jar
当你设置CURLOPT_COOKIEJAR属性设置一个文件时,
文件会被创建,并且在执行curl_easy_cleanup函数之后,所有接受到的cookie信息会被存储到该文件中。
这样使得所有的cookie信息会在适当的时候发送出去。

[译]Cookies Without Chocolate Chips的更多相关文章

  1. linux c libcurl的简单使用(转)

    curl是Linux下一个非常著名的下载库,通过这个库,可以很简单的实现文件的下载等操作.看一个简单的例子: #include <curl/curl.h> #include <std ...

  2. curl 基本使用简介

    curl是Linux下一个非常著名的下载库,通过这个库,可以很简单的实现文件的下载等操作.看一个简单的例子: #include <curl/curl.h> #include <std ...

  3. Libcurl细说

    libcurl教程   原文地址:http://curl.haxx.se/libcurl/c/libcurl-tutorial.html 译者:JGood(http://blog.csdn.net/J ...

  4. JAVA经典总结

    Java经典实例(第二版) 1. 获取环境变量 Java代码 1. System.getenv("PATH"); 2. System.getenv("JAVA_HOME& ...

  5. 2016 Google code jam 答案

    二,RoundC import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundE ...

  6. Brownie Slicing(二分枚举答案)

    描述 Bessie has baked a rectangular brownie that can be thought of as an RxC grid (1 <= R <= 500 ...

  7. Flutter Widget框架概述

    Flutter Widget采用现代响应式框架构建,这是从 React 中获得的灵感,中心思想是用widget构建你的UI. Widget描述了他们的视图在给定其当前配置和状态时应该看起来像什么.当w ...

  8. Hamcrest使用

    What is Hamcrest? 什么是Hamcrest?   Hamcrest is a library of matchers, which can be combined in to crea ...

  9. Hamcrest Tutorial

    Java Hamcrest Home Hamcrest Tutorial Introduction Hamcrest is a framework for writing matcher object ...

随机推荐

  1. CCCC2017大区赛补完

    L2-2 多项式除法 这题看懂题意就是个模拟 L3-2 周游世界 想法是相邻点连边,然后跑最短路,当最短路相同时候,比较之前经过的换乘数,取最小的作为方案 但是这样只过了2个点……? 网上dalao们 ...

  2. Eclipse-Java代码规范和质量检查插件-SonarLint

    SonarQube(Sonar)之前的提供的本地工具是需要依赖SonarQube服务器的,这样导致其运行速度缓慢. 新出的SonarLint的扫描引擎直接安装在本地,速度超快,实时探测代码技术债务,给 ...

  3. 保持WCF服务端与客户端的长连接

    背景 客户端与服务端使用WCF建立连接后:1.可能长时间不对话(调用服务操作):2.客户端的网络不稳定. 为服务端与客户端两边都写“心跳检测”代码?不愿意. 解决 设置inactivityTimeou ...

  4. golang 跨平台编译——go 在windows上编译Linux平台的程序(Cross Compilation from Windows to Linux/Ubuntu)

    Go Cross Compilation from Windows to Linux/Ubuntu I have GO 1.7 installed on my Windows 10. I create ...

  5. [python]pycharm画图插件matplotlib、numpy、scipy的下载与安装

    最近在用pycharm学习python语言,不得不感叹python语言的强大与人性化! 但对于使用pycharm画图(较复杂的图)就要用到几个插件了,即matplotlib.numpy和scipy!但 ...

  6. Spring_2_Spring中lazy-init和scope属性

    1)springTest类: public class springTest { @Test public void instanceSpring() { AbstractApplicationCon ...

  7. Silverlight+WCF实现跨域调用

    在这篇文章中.WCF扮演server,向外提供LoginVaild服务.Silverlight扮演client.调用WCF提供的LoginVaild服务.思路有了.以下进行代码实现. 数据库脚本实现 ...

  8. 合并小图片利器TexturePacker GUI

    合并小图片,能够非常大的节省网络开销.尤其如今的站点非常喜欢使用大量的小图标来做一些友好提示.当然使用图片文字也是一种选择. 只是这里推荐的是TexturePacker GUI ,这个确实是一款利器. ...

  9. .net Core使用Orcle官方驱动连接数据库 C#参考教程 http://www.csref.cn

    .net Core使用Orcle官方驱动连接数据库   最近在研究.net Core,因为公司的项目用到的都是Oracle数据库,所以简单试一下.net Core怎样连接Oracle. Oracle官 ...

  10. TCP从连接到释放过程全解

    參考书籍:<计算机网络第5版> TCP是面向连接的协议,採用C/S模型建立连接,由client主动发起连接请求,server端允许请求的模式建立连接,通常称为三次握手建立TCP连接. 准备 ...