开发者

Curl copy command in PHP

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜