开发者

Generate and save a custom cookie on the serverside

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   / 开发者_如何学Go  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


http://xiix.wordpress.com/2006/03/23/mozillafirefox-cookie-format/


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜