[译]Cookies Without Chocolate Chips
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的更多相关文章
- linux c libcurl的简单使用(转)
curl是Linux下一个非常著名的下载库,通过这个库,可以很简单的实现文件的下载等操作.看一个简单的例子: #include <curl/curl.h> #include <std ...
- curl 基本使用简介
curl是Linux下一个非常著名的下载库,通过这个库,可以很简单的实现文件的下载等操作.看一个简单的例子: #include <curl/curl.h> #include <std ...
- Libcurl细说
libcurl教程 原文地址:http://curl.haxx.se/libcurl/c/libcurl-tutorial.html 译者:JGood(http://blog.csdn.net/J ...
- JAVA经典总结
Java经典实例(第二版) 1. 获取环境变量 Java代码 1. System.getenv("PATH"); 2. System.getenv("JAVA_HOME& ...
- 2016 Google code jam 答案
二,RoundC import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundE ...
- Brownie Slicing(二分枚举答案)
描述 Bessie has baked a rectangular brownie that can be thought of as an RxC grid (1 <= R <= 500 ...
- Flutter Widget框架概述
Flutter Widget采用现代响应式框架构建,这是从 React 中获得的灵感,中心思想是用widget构建你的UI. Widget描述了他们的视图在给定其当前配置和状态时应该看起来像什么.当w ...
- Hamcrest使用
What is Hamcrest? 什么是Hamcrest? Hamcrest is a library of matchers, which can be combined in to crea ...
- Hamcrest Tutorial
Java Hamcrest Home Hamcrest Tutorial Introduction Hamcrest is a framework for writing matcher object ...
随机推荐
- P1165 日志分析 洛谷
https://www.luogu.org/problem/show?pid=1165 题目描述 M 海运公司最近要对旗下仓库的货物进出情况进行统计.目前他们所拥有的唯一记录就是一个记录集装箱进出情况 ...
- 当遇到Mac的Excel或者Word老是重复崩溃的时候
打开Number,新建文件然后导出为Excel.之后再用Excel打开,一切都OK了.
- IPv6 Ready Logo测试环境搭建
最新的IPv6 Ready Logo tool http://interop.ipv6.org.tw/CERouter/ 安装最新的tool,要求FreeBSD在8.0以上 uname -r查看版本 ...
- Excel数据字典转换为PDM(且显示表名、字段相应的中文描写叙述)
在工作中遇到了一个问题就是把Excel数据字典转换为PDM. 可是转换完毕了全是英文,原来对表名.字段名的中文描写叙述就没有了. 且对于这个问题在powerdesigner15.2以后能够直接完毕.可 ...
- kvc VS kvo
Kvo是Cocoa的一个重要机制,它主要是用于对一个属性的新旧值的监控. 例如说依据A(数 据类)的某个属性值变化,B(view类)中的某个属性做出对应变化.对于MVC,kvo应用的地方很广泛. 使用 ...
- log4j 具体解释
通常,我们都提供一个名为 log4j.properties的文件.在第一次调用到Log4J时,Log4J会在类路径(../web-inf/class/当然也能够放到其他不论什么文件夹.仅仅要该文件夹被 ...
- js逻辑执行判断
两个变量或者函数,如果与的关系,a && b,如果a是真则在运行b,如果a是假则不运行b了:如果是或的关系,前者是真则不运行后边的了,否则反过来. 举个例子: <span cla ...
- php 获取今天,本周,本月,三个月内,半年内,今年的开始和结束时间
$now = time(); //今天 $today_audit_num = 0; $today_use_num = 0; $beginTim ...
- .net Core使用Orcle官方驱动连接数据库 C#参考教程 http://www.csref.cn
.net Core使用Orcle官方驱动连接数据库 最近在研究.net Core,因为公司的项目用到的都是Oracle数据库,所以简单试一下.net Core怎样连接Oracle. Oracle官 ...
- 【智能家居篇】wifi网络结构(下)
转载请注明出处:http://blog.csdn.net/Righthek 谢谢. 因为WIFI网络具有移动性,同一时候WIFI以无线电波作为传输媒介,这样的媒介本质上是开放的,且easy被拦截,不论 ...