zoukankan      html  css  js  c++  java
  • CURL post请求

     1 /*****post请求******/
     2     public function postDataCurl($url,$data=array()){
     3         $this->checkSumBuilder();        //发送请求前需先生成checkSum
     4         if(!empty($data)){
     5             $json=json_encode($data);
     6         }else{
     7             $json="";
     8         }
     9         $timeout = 5000; 
    10         $http_header = array(
    11             'AppKey:'.$this->AppKey,
    12             'Nonce:'.$this->Nonce,
    13             'CurTime:'.$this->CurTime,
    14             'CheckSum:'.$this->CheckSum,
    15             'Content-Type: application/json;charset=utf-8;',
    16             'Content-Length: ' . strlen($json)
    17         );
    18         $ch = curl_init(); 
    19         curl_setopt ($ch, CURLOPT_URL, $url);
    20         curl_setopt ($ch, CURLOPT_POST, 1);
    21         curl_setopt ($ch, CURLOPT_POSTFIELDS, $json);
    22         curl_setopt ($ch, CURLOPT_HEADER, false); 
    23         curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header);
    24         curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);
    25         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    26         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    27        
    28         $result = curl_exec($ch); 
    29         if (false === $result) {
    30             $result =  curl_errno($ch);
    31         }
    32         curl_close($ch); 
    33         return json_decode($result,true) ;
    34     } 
  • 相关阅读:
    python中创建实例属性
    Python中if __name__ == "__main__": 的理解
    模块
    python函数式编程
    python-复杂生成式
    生成器的测试
    mysql乱码配置
    javascript
    Sql Server 2008 R2 下载地址
    Microsoft Data Access Components 2.8
  • 原文地址:https://www.cnblogs.com/d-kis/p/5689298.html
Copyright © 2011-2022 走看看