doubenggua9430 2017-10-13 12:56
浏览 167
已采纳

curl - 从cookie-jar文件中选择特定的cookie值

How do you select the value of a specific cookie from a cookie-jar file for future requests?

I need to submit a form on a website that requires that the current sessionId be passed as form data. The sessionId is set as a cookie on the login page.

First request (authentication)

curl -d "username=my_user&pass=my_pass" http://mywebsite.com/login.php -c, --cookie-jar  my-cookies

Second request (form submit)

curl -d "sessionId=jk5lkdr7cdqkn1ptqa0rmndbr7&formField1=abc&formField2=def" http://mywebsite.com/getReport.php -b, --cookie my-cookies

In the above request data, I've manually copied the session id from the cookie file. The cookie file looks like this. (sessionId = PHPSESSID)

# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

mywebsite.com   FALSE   /   FALSE   0   PHPSESSID   jk5lkdr7cdqkn1ptqa0rmndbr7
.mywebsite.com  TRUE    /   FALSE   1516507485  info    crownandcaliber%40mediaiqdigital.com
.mywebsite.com  TRUE    /   FALSE   1507867485  pref    deleted
.mywebsite.com  TRUE    /   FALSE   0   affiliate_flag  Y3Jvd25hbmRjYWxpYmVyQG1lZGlhaXFkaWdpdGFsLmNvbQ%3D%3D
.mywebsite.com  TRUE    /   FALSE   0   cookie  name%3ATm8gYWR2ZXJ0aXNlciBuYW1lIGF2YWlsYWJsZQ%3D%3D%3B

Is there a way for me to progammatically pull the value of the PHPSESSID cookie which is set in the first request into the form data for the second request?

</div>
  • 写回答

1条回答 默认 最新

  • dsafgdafgdf45345 2017-10-13 15:11
    关注

    The code below reads a 5th line from a file youfilewithcookie, gets content of a 7th column and reads it in a variable called sessId.

    awk 'NR==5' youfilewithcookie | awk {'print $7'} | (read sessId; yourculcommand here with $sessId)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)