PHP-curl传参

当传参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);

 

 

PHP-curl传参

 

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下载文件


下一篇:android_定义多个Activity及跳转