我正在执行此 curl 请求以在 python 中获取一些数据,如何获取 curl 请求的 session ID 以便我可以再次使用。
commands.getoutput("curl -H \"Content-Type:application/json\" -k -u username:password -X GET https://10.39.11.4/wapi/v2.7/member -s"
请您参考如下方法:
curl 有一个内置的 cookie jar,用于存储 cookie 并将它们发送回服务器。
为了将 cookie 存储在 cookie jar 中,我们使用 -c 标志并为其指定我们希望存储 cookie 的文件的名称。
$ curl -X POST -c cookies.txt -u "user1:password1" website.com/login
$ cat cookies.txt
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
#HttpOnly_quiet-waters-1228.herokuapp.com FALSE / FALSE 0 _curl_test_app_rails_
session cm53d2RJN1VncV........
在那里你可以找到 session ID。
正如 Daniel Stenberg(cURL 的创始人)所提到的:
在随后的 curl 命令行中使用 -b cookies.txt 来使用这些 cookie
