$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;
}