PHP uses the curl method to post data to the api interface. most of the HTTP requests of the API are GET. therefore, no matter AJAX or PHP is used for secondary processing, the returned data can be obtained, however, the HTTP request method of some APIs is POST, so we need to use curl, which is also relatively simple. the code is as follows:
'Thekeyvalue'); $ json_data = postData ($ url, $ data); $ array = json_decode ($ json_data, true); echo''; 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.jb51.net/"); // Construct the Origin curl_setopt ($ ch, CURLOPT_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 ;}?>For more articles about the code that uses the CURL method to POST data to the API in PHP, refer to the PHP Chinese website!