Crazy lens

PHP用CURL发送application/json 数据
<?php $headers = array(   "Content-type: applica...
扫描右侧二维码阅读全文
26
2020/04

PHP用CURL发送application/json 数据

<?php

$headers = array(
  "Content-type: application/json"
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); //设置超时
if(0 === strpos(strtolower($url), 'https')) {
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //对认证证书来源的检查
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //从证书中检查SSL加密算法是否存在
}
curl_setopt($ch, CURLOPT_POST, TRUE);
$data = array(0=>1,1=>2);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
$rtn = curl_exec($ch);//CURLOPT_RETURNTRANSFER 不设置  curl_exec返回TRUE 设置  curl_exec返回json(此处) 失败都返回FALSE
curl_close($ch);
最后修改:2020 年 04 月 26 日 12 : 17 AM
如果觉得我的文章对你有用,请随意赞赏

发表评论