zoukankan      html  css  js  c++  java
  • 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;}
  • 相关阅读:
    Maximum Depth of Binary Tree
    Single Number
    Merge Two Sorted Lists
    Remove Nth Node From End of List
    Remove Element
    Remove Duplicates from Sorted List
    Add Two Numbers
    编译视频直播点播平台EasyDSS数据排序使用Go 语言 slice 类型排序的实现介绍
    RTMP协议视频直播点播平台EasyDSS在Linux系统中以服务启动报错can’t evaluate field RootPath in type*struct排查
    【解决方案】5G时代RTMP推流服务器/互联网直播点播平台EasyDSS实现360°全景摄像机VR直播
  • 原文地址:https://www.cnblogs.com/jami918/p/3441129.html
Copyright © 2011-2022 走看看