• 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;}
  • 相关阅读:
    覆盖式发布与非覆盖式发布
    GIT
    Web Service返回符合Xml Schema规范的Xml文档
    下拉渐显菜单
    计算网页上坐标的距离
    初识交互设计
    良好用户体验-实现过程!
    做 用户调研?
    这个没什么技术含量,实现起来很简单?
    SQL SERVER 登录问题!该用户与可信的Sql Server连接无关联
  • 原文地址:https://www.cnblogs.com/jami918/p/3441129.html
Copyright © 2020-2023  润新知