How to post data to the API using curl in PHP
The HTTP Request Method of most APIS is get. Therefore, no matter Ajax or PHP is used for secondary processing, the returned data can be obtained.
However, if the HTTP Request Method of Some APIs is post, we need to use curl.
In fact, it is also relatively simple, on the Code:
<? PHP $ 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); echo '<PRE>'; print_r ($ array); function postdata ($ URL, $ data) {$ CH = curl_init (); $ timeout = 300; curl_setopt ($ ch, curlopt_url, $ URL); curl_setopt ($ ch, curlopt_referer, "http://www.jincon.com /"); // construct curl_setopt ($ ch, curlop T_post, true); curl_setopt ($ ch, curlopt_postfields, $ data); curl_setopt ($ ch, curlopt_returntransfer, 1); curl_setopt ($ ch, curlopt_connecttimeout, $ timeout ); $ handles = curl_exec ($ ch); curl_close ($ ch); return $ handles ;}?>
Source: http://www.jincon.com/archives/3/
Now, we have a new blog: http://www.jincon.com/. you are welcome to visit each other... Continue to share relevant articles later.