我正在使用curl更新远程站点中的一些字段。但我完成的是: 我能够登录到远程站点,能够获取我需要在curl请求中使用的csrf令牌。但我无法在curl中根据需要设置标头参数 测试网址为http://singh.mobi//vishal/curl/proposalform1.php
我的代码就像:
$ch1 = curl_init();
$data_string = '{""proposal"":{""id"":36854,""name"":""New proposal #9"",""template_id"":5107,""sections"":[],""custom_tokens"":[],""reload_template"":true}}';
curl_setopt($ch1, CURLOPT_URL, "http://alpha.niftyquoter.com/proposals/36854?cool_edit=true");
//$ch = curl_init('http://api.local/rest/users');
curl_setopt($ch1, CURLOPT_COOKIEJAR, '/home/brilliantmind/public_html/singh.mobi/vishal/curl/'.$cookie);
curl_setopt($ch1, CURLOPT_COOKIEFILE, '/home/brilliantmind/public_html/singh.mobi/vishal/curl/'.$cookie);
curl_setopt($ch1, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch1, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json', 'Origin: http://alpha.niftyquoter.com', 'Accept-Encoding: gzip,deflate,sdch',
'X-CSRF-Token: $authenticity_token','Accept: application/json','Referer: http://alpha.niftyquoter.com/proposals/36854?edit=true'
)
);
$result = curl_exec($ch1);
$header = curl_getinfo( $ch1 );
echo '<pre>';
print_r($header);
curl_close($ch1);
echo $output;
答案 0 :(得分:0)
我更正了问题,错误就在这行'X-CSRF-Token:$ authenticity_token' 需要在单引号之外传递$ authenticity_token。