php curl get post

post有3种。

1、post方式

privatefunction send_post($url,$post_data){
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  $response = curl_exec($ch);
  $errno = curl_errno($ch);
  $errmsg = curl_error($ch);
  curl_close($ch);if($errno !=0){
   return_param($errmsg.':'.$errno);}return json_decode($response);}

2、post方式

function http_post($url, $post_array = array(), $ctime =3, $timeout =4){if(!is_array($post_array))return FALSE;

	$post_data ='';foreach($post_array as $key => $var){
		$post_data .= $key .'='. urlencode($var).'&';}
	$post_data = substr($post_data,0,-1);

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, FALSE);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $ctime);
	curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
	curl_setopt($ch, CURLOPT_POST, TRUE);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	$output = curl_exec($ch);
	curl_close($ch);return $output;}

3、post方式

function _xpost($url, $p){
	$f ='';
	$data ='';foreach($p as $k => $v){
		$data .= $f . $k .'='. urlencode($v);
		$f ='&';}
	$curl = curl_init($url);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,1);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_POST,1);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
	$res = curl_exec($curl);if(curl_errno($curl)){
		echo 'Curl error: '. curl_error($curl);}
	curl_close($curl);return $res;}

1、get方式传参

function http_get($url, $ctime =3, $timeout =4){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $ctime);
	curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

	$result = curl_exec($ch);
	curl_close($ch);return $result;}

转载于:https://www.cnblogs.com/jami918/p/3441129.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值