码迷,mamicode.com
首页 > Web开发 > 详细

CURL post请求

时间:2016-07-20 19:26:08      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

 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     } 

 

CURL post请求

标签:

原文地址:http://www.cnblogs.com/d-kis/p/5689298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!