如何用这个curl编写curl PHP脚本

时间:2015-07-29 23:19:44

标签: php curl

我正在尝试编写php脚本来运行curl作业,这里是创建票证的curl查询

     curl -X POST -H "Content-Type: application/json" -H
    "username:username" -H "password:password" --data
   '{"serviceName":"CREATE_AVENT","keyValues":{"title":
    "test","actionableevent_priority": "Minor","source":
    "TEC","requester_login": "user"}}' -k
   https://createticket.com/arsys/rest/service/createTicket

这是我在php中编写的脚本

$url="https://createticket.com/arsys/rest/service/createTicket";
$field=array("serviceName"=>"CREATE_AVENT","keyValues"=>array("title"=>"test","actionableevent_priority"=>"Minor","source"=>"TEC","requester_login"=>"user"));
$data_string = json_encode($field);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CAINFO, "/var/www/xxx/cacert.pem");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','username:username','password:password'));

$output = curl_exec($ch);
print_r($output);
$info = curl_getinfo($ch);
$err=curl_error($ch);
print_r($err);
print "\n";
curl_close($ch);

当我执行curl查询时,它返回票证ID并在系统中创建票证。 但是,当我运行脚本时,它不会返回任何内容以及系统中没有票证。 谁能告诉我这个脚本有什么问题?

1 个答案:

答案 0 :(得分:0)

从评论中,我看到php代码无法验证服务器证书。如果您愿意,可以选择忽略证书。

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

我在this question.

中找到了更详细的配置