PHP-curl传参

2021-03-03 17:29

阅读:288

标签: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


评论


亲,登录后才可以留言!