如何从curl获取会话ID并将其再次用于下一个GET请求

use*_*715 1 python curl

我正在做这个curl请求以获取python中的一些数据,我如何获取curl请求的会话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"
Run Code Online (Sandbox Code Playgroud)

Noo*_*fri 5

curl有一个内置的cookie罐,用于仅存储cookie并将它们发送回服务器。

要将cookie存储在cookie罐中,我们使用-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........
Run Code Online (Sandbox Code Playgroud)

在这里您可以找到会话ID。

正如Daniel Stenberg所提到的

在随后的curl命令行中使用-b cookies.txt来使用这些cookie

  • 然后在随后的 curl 命令行中使用 `-b cookies.txt` 以在以下传输中使用这些 cookie (2认同)