Home >Backend Development >PHP Tutorial >PHP calls the interface to transmit json data using the post method
This article mainly introduces the PHP calling interface to use the post method to transmit json data. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
First, convert the data into json format, then call the interface through the curl method and pass the parameters
The code is as follows:
$keyword = urlencode($_POST['keyword']); $parameters = json_encode(array('keyWord'=>$keyword,'areaCode'=>'*')); $post_data['appToken'] = "323ds7674354fds32fdsda60173";//随便写的 $post_data['parameters'] = $parameters; $url = 'http://serde.com/compadddvd/index';//随便写的 $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//用post方法传送参数 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch);
Then just return the data.
Related recommendations:
php post json parameter transmission and reception processing method
The above is the detailed content of PHP calls the interface to transmit json data using the post method. For more information, please follow other related articles on the PHP Chinese website!