How to call interface api in php

小云云
Release: 2023-03-22 22:02:01
Original
34347 people have browsed it

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 );
Copy after login

Related recommendations:

Detailed introduction to PHP’s API interface

Detailed explanation of PHP server-side API and interface development

PHP for API interface testing

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!