• 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;}
  • 相关阅读:
    苹果将首次采用HTML5直播发布会 狼人:
    Python 3.2 alpha 2发布 狼人:
    下一代Linux文件系统Btrfs走向成熟 狼人:
    Hello! 404 狼人:
    退格回车控制台输入密码
    poj 3233 Matrix Power Series
    地址参考clang: error: linker command failed with exit code 1 (use v to see invocation)
    文本截断JQuery为textarea添加maxlength,并且兼容IE
    代码下载Html5初探视频元素video示例
    c# 限制textbox的输入范围和长度(长度不用maxlength方法)
  • 原文地址:https://www.cnblogs.com/jami918/p/3441129.html
Copyright © 2020-2023  润新知