Curl and cookie

落花浮王杯 提交于 2020-01-13 04:45:00

问题


I'm using cURL to log in a website, but I don't know how to get/use the cookies I get.

Does anybody has an idea?

Thanks


回答1:


http://ask.metafilter.com/18923/How-do-you-handle-authentication-via-cookie-with-CURL




回答2:


Maybe, this example will help...

#!/bin/bash
COOKIE_FILE="cookie.tmp"
MAIN_URL="http://localhost:8080/monitor"

if [ -e $COOKIE_FILE ] ; then
    rm $COOKIE_FILE
fi

curl -d "j_username=user&j_password=pass" -c $COOKIE_FILE "$MAIN_URL/j_spring_security_check"

DATA=`curl -b $COOKIE_FILE "$MAIN_URL/host/list.json"`

curl --get -b $COOKIE_FILE "$MAIN_URL/host/addHost.json?newHostAddress=192.168.77.197&newHostPort=9990"

rm $COOKIE_FILE



回答3:


just add

curl_setopt($curl, CURLOPT_COOKIE, 'someKey=' . $_COOKIE['someVal . '; path=/');

and you have a cookie in your request. if u need more then one cookie, look up this function on php.net and find "cookie file" or if u need to save cookies from the response find "cookie jar"



来源:https://stackoverflow.com/questions/1860030/curl-and-cookie

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!