[译]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 ...
随机推荐
- T1003 电话连线 codevs
http://codevs.cn/problem/1003/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 一个国家有n个城市 ...
- java反射-使用反射来操纵方法
一个类的主要成员时方法,辣么我们通过反射获取到一个类的所有方法信息后,总的寻找一种方式去操作调用这些方法,这样反射才有意义有意思. Method对象有一个方法invoke. public O ...
- yum install tree 出错primary.sqlite.bz2: [Errno -1] Metadata file does not match checks 解决办法
Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfilehttp://ftp.sjtu.edu.cn/centos ...
- android账号与同步之账号管理
在android提供的sdk中,samples文件夹下有一个叫SampleSyncAdapter的演示样例,它是一个账号与同步的实例,比方Google原始的android手机能够使用Google账号进 ...
- Kinect驱动的人脸实时动画
近期几年.realtime的人脸动画開始风声水起.不少图形图像的研究者開始在这个领域不断的在顶级会议siggraph和期刊tog上面发文章. 随着kinect等便宜的三维数据採集设备的运用.以及其功能 ...
- 策略模式&反射
业务代码 class Operate { public string _firstKey; public string _secondKey; public string _extendKey; pu ...
- rsync 3.1.1源代码编译安装配置
http://rsync.samba.org/ rsync-3.1.1.tar.gz ---0.卸载rpm # yum remove rsync -----1.安装: tar -zxvf rsync- ...
- npm won't install packages “npm ERR! network tunneling socket could not be established, cause=Parse Error”
昨天在使用npm安装react-native的时候一直报网络不能connection,可是在浏览器中直接访问时是成功,搜索百度无果,最后在google中找到了这个解决方案:http://stackov ...
- 【bzoj1787】&【bzoj1832】[Ahoi2008]Meet 紧急集合 & 聚会
bzoj1787就是bzoj1832 bzoj1832 空间和时间少了一些... 求三个结点到一个结点距离之和最小的结点以及距离和 求出两两lca,其中有两个相同,答案则为另一个 感觉就是一大暴力.. ...
- office文档、图片、音/视频格式转换工具
1.音频/视屏转换工具VLC https://wiki.videolan.org/Mp3/#Container_formats http://wenku.baidu.com/view/ba73ac5 ...