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;}

你可能感兴趣的:(post)