是否可以使用 CURL 设置 cookie 内容? [英] Is it possible to set the cookie content with CURL?

查看:40
本文介绍了是否可以使用 CURL 设置 cookie 内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法,为 CURL 指定 cookie 数据.我找到了一些关于如何从访问过的页面保存 cookie 的解决方案,但这不是我需要的.我想要的是,自己为cookie写数据,所以CURL使用它.

I have been searching for a way, to specify the cookie data for CURL. I have found some solutions on how to save the cookies from a visited page, but that's not what I need. What I want is, to write the data for the cookie myself, so CURL uses it.

推荐答案

你真的应该阅读文档 - 它列出了您所期望的关键字,并包含许多有用的信息:

You really should read the documentation - it's listed with exactly the keywords you'd expect and contains a lot of helpful info:

-b, --cookie

-b, --cookie

(HTTP) 将数据作为 cookie 传递给 HTTP 服务器.据说先前在Set-Cookie:"行中从服务器接收的数据.数据的格式应为NAME1=VALUE1;NAME2=VALUE2".

(HTTP) Pass the data to the HTTP server as a cookie. It is supposedly the data previously received from the server in a "Set-Cookie:" line. The data should be in the format "NAME1=VALUE1; NAME2=VALUE2".

如果行中没有使用="符号,则将其视为文件名用于读取以前存储的 cookie 行,应该使用在这个会话中,如果它们匹配.使用此方法还可以激活cookie 解析器"也将使 curl 记录传入的 cookie,如果您将它与 -L 结合使用,这可能会很方便,--位置选项.从中读取 cookie 的文件的文件格式应该是纯 HTTP 标头或 Netscape/Mozilla cookie 文件格式.

If no '=' symbol is used in the line, it is treated as a filename to use to read previously stored cookie lines from, which should be used in this session if they match. Using this method also activates the "cookie parser" which will make curl record incoming cookies too, which may be handy if you're using this in combination with the -L, --location option. The file format of the file to read cookies from should be plain HTTP headers or the Netscape/Mozilla cookie file format.

请注意,使用 -b、--cookie 指定的文件仅用作输入.文件中不会存储任何 cookie.要存储 cookie,请使用 -c,--cookie-jar 选项,或者您甚至可以使用 -D、--dump-header 将 HTTP 标头保存到文件中!

NOTE that the file specified with -b, --cookie is only used as input. No cookies will be stored in the file. To store cookies, use the -c, --cookie-jar option or you could even save the HTTP headers to a file using -D, --dump-header!

如果此选项设置多次,最后一个将是用过的.

If this option is set more than once, the last one will be the one that's used.

这篇关于是否可以使用 CURL 设置 cookie 内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆