在服务器端生成并保存自定义 cookie
我想生成一个具有特定名称/值的cookie(在服务器端,因此不会有任何浏览器)并将其保存在文本文件中(例如使用 fopen )。稍后我计划将该 cookie 与 cURL 一起使用。问题是我不明白cookie格式是什么以及我应该如何保存它。当我查看 cURL 保存的 cookie 时,我有类似这样的内容,
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
www.example.com FALSE / FALSE 0 ASP.NET_SessionId 3ddldk5iccxrj45fsl2ctrd
www.example.com FALSE / FALSE 32522347 sccouscIX 548913113
我不明白空格以及应该使用什么方法来生成工作 cookie 。作为概念证明,我想生成一个简单的 cookie,名称为:exampleId,值 000000000
exampleId 000000000 / www.example.org
更新只是为了确保问题得到理解:我需要生成一个自定义 cookie,而不是获取由其他网站生成的 cURL 的 cookie。 我还在curl网站上找到了原始Netscape cookie规范
I would like to generate a cookie (on the server side so there won't be any browser) with specific name/values and save it in a text file (e.g with fopen ). Later I'm planning to to use that cookie with cURL . The problem is that I don't understand what's the cookie format and how should I save it . When I look on the cookies saved by cURL I have something like this
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
www.example.com FALSE / FALSE 0 ASP.NET_SessionId 3ddldk5iccxrj45fsl2ctrd
www.example.com FALSE / FALSE 32522347 sccouscIX 548913113
I don't understand the spaces and what method I should use to generate a working cookie . As proof of concept I would like to generate a simple cookie with name : exampleId and value 000000000
exampleId 000000000 / www.example.org
Update just to make sure the question is understood: I need to generate a custom cookie not to get one with cURL generated by other websites.
I also found the Original Netscape cookie specification on curl website
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://xiix.wordpress.com/2006/03/23/ mozillafirefox-cookie-格式/
http://xiix.wordpress.com/2006/03/23/mozillafirefox-cookie-format/
我认为 http://coderscult.com /php/php-curl/2008/05/20/php-curl-cookies-example/ 的代码可以准确演示您正在寻找的内容。
I think that http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/ has the code to demo exactly what you are looking for.
您不需要手动解释 cookie 文件。 Curl 可以设置 cookie,将其存储在您指定的位置,并从中加载数据。我猜你是在 php 中这样做的。 php.net 网站对此有很好的文档。
这就是我所做的
HTTP LIVE 标头 Firefox 插件
当您调用该网址(例如登录网址)时,该插件会告诉您需要发布的所有内容。
当您使用这些post值(在curl_set_opt中设置)调用url时,curl会将相关数据存储在您指定的cookie文件中。
在随后的调用中,您告诉curl 加载此cookie。
You don't need to interpret the cookie file manually. Curl can set the cookie, store it in a place you specify, and the load data from it. I presume you are doing this in php. The php.net site is pretty well document on this.
Here is what i did
HTTP LIVE headers a plugin for firefox
When you call the url(say the login url) this plugin will tell you all that you need to post.
When you call the url with these post values (set in curl_set_opt), curl will store the relevant data in the cookie file you specify.
In your subsequent call you tell curl to load this cookie.