Home  >  Article  >  Backend Development  >  Code for POST data to API interface using CURL method under PHP_PHP Tutorial

Code for POST data to API interface using CURL method under PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:12:54774browse

Actually, it is relatively simple. Upload the code:

Copy the code The code is as follows:


$url = 'http://127.0.0.1/test.php';//The link pointed to by POST
$data = array(
'access_token'=>'thekeyvalue'
);  

 $json_data = postData($url, $data);    
 $array = json_decode($json_data,true); ; ;

function postData($url, $data)
{ $ch = curl_init();
$timeout = 300; topt($ch, CURLOPT_URL, $url ; ch, CURLOPT_POSTFIELDS, $data); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$handles = curl_exec($ch);
curl_close($ch);                                                                                                                                                                                



http://www.bkjia.com/PHPjc/326623.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/326623.html
TechArticle

Actually, it’s relatively simple, just upload the code: Copy the code and the code is as follows: ?php $url = 'http:// 127.0.0.1/test.php';//The link pointed to by POST $data = array( 'access_token'='thekeyvalue' ); $jso...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn