码迷,mamicode.com
首页 > Web开发 > 详细

PHP-curl传参

时间:2021-01-11 11:10:40      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ima   inf   timestamp   enc   tps   ===   tran   content   code   

当传参data为二维数组,Content-Type: application/x-www-form-urlencoded时,

$a = array(‘a‘,‘b‘,‘c‘);

$a[‘d‘] = array(‘e‘,‘f‘,‘g‘);

传参为二维数组时

$a[‘d‘] = json_encode($a[‘d‘]);

$data = http_build_query($data);

$this->httpcurl_post($url,$data);

 

 

技术图片

 

private function httpcurl_post($url,$data) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$header = array(
‘Content-Type: application/x-www-form-urlencoded‘,
‘projectId:‘.$this->projectId,
‘secret:‘.$this->do_secret,
‘timestamp:‘.$this->timestamp
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

// if(substr($url, 0,5) == ‘https‘) {
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// }

//post提交方式
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

$rtn = curl_exec($ch);

// if($rtn === false) {
// //var_dump(curl_error($ch));exit;
// trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR);
// }
curl_close($ch);

return $rtn;

PHP-curl传参

标签:ima   inf   timestamp   enc   tps   ===   tran   content   code   

原文地址:https://www.cnblogs.com/PHP-Jason/p/14252086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!