This article mainly shares with you the method of calling the interface API in PHP. I hope it can help you.
他会提供相应接口给你的,具体调用方法就相当于讲求某个链接。 如: http://localhost/operate.php?act=get_user_list&type=json 在这里operate.php相当于一个接口,其中get_user_list 是一个API(获取用户列表),讲求返回的数据类型为JSON格式。 你只需要在你PHP代码中执行这条链接他就会返回。 GET方式的直接使用 $file_contents = file_get_content('http://localhost/operate.php?act=get_user_list&type=json') POST方式得用下面的(需要开启PHP curl支持)。 $url = 'http://localhost/operate.php?act=get_user_list&type=json'; $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 ); curl_setopt ( $ch, CURLOPT_POST, 1 ); //启用POST提交 $file_contents = curl_exec ( $ch ); curl_close ( $ch );
Related recommendations:
Detailed introduction to PHP’s API interface
Detailed explanation of PHP server-side API and interface development
The above is the detailed content of How to call interface api in php. For more information, please follow other related articles on the PHP Chinese website!