php調用介面api的方法

來源:互聯網
上載者:User
本文主要和大家分享php調用介面api的方法,希望能協助到大家。

他會提供相應介面給你的,具體調用方法就相當於講求某個連結。如: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 );

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.