<?php $url = 'http://127.0.0.1/test.php'; //接口地址 $data = array( 'key1'=>'value1', 'key2'=>'value2' ); $json_str = curl_post($url, $data); $json_arr = json_decode($json_str, TRUE); var_dump($json_arr); function curl_post($url, $data) { $ch = curl_init(); $timeout = 300; curl_setopt($ch, CURLOPT_URL, $url); // 請求地址 curl_setopt($ch, CURLOPT_REFERER, "http://www.jianbin.info/ "); // 請求來源地址 curl_setopt($ch, CURLOPT_POST, true); // POST請求方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // 提交參數 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 以文件流的形式返回 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 請求超時時間 $result = curl_exec($ch); curl_close($ch); return $result; }