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, 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:
Copy codeThe 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 );
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.bitsCN.com/"); // Construct a path
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;
}
?>