I am trying to copy
curl -c cookie_jar -H "Content-Type: application/json" -d '{"username" : "admin", "password" : "admin"}' http://jira:8080/rest/auth/latest/session
in PHP but I cannot seem to get it working.
I have
curl_setopt($curl,CURLOPT_URL, $loginUrl );
curl_setopt(开发者_运维知识库$curl,CURLOPT_POST, true );
curl_setopt($curl,CURLOPT_POSTFIELDS, '{"username" : "admin", "password" : "admin"}');
curl_setopt($curl,CURLOPT_COOKIEJAR, '/tmp/cookiejar' );
curl_setopt($curl, CURLOPT_HTTPHEADERS,array('Content-Type: application/json'));
curl_exec( $curl );
Any help?
You actually need the CURLOPT_COOKIEFILE option, actually. COOKIEJAR species where to write new cookies to. COOKIEFILE is for loading existing cookies into CURL. Your PHP equivalent right now is not sending any cookies - it's only recording them. Add this, and you should be good to go:
curl_setopt($curl,CURLOPT_COOKIEFILE, '/tmp/cookiejar' );
^^^^---the big difference.
精彩评论