php获取post全部数据,php获取post数据方法详解

1. 发送post数据

$data = '{

"id": "17999030",

"method": "sayHello",

"jsonrpc": "2.0",

"params":

{

"acmac": "00E0614CA7C6",

"acconf_version": "2015-10-28-09-45"

}

}';$url = "http://wifi.doucube.com/index.php/interface/device/ConfHeartbeat.html";$res = http_request($url, $data);var_dump($res);//HTTP请求(支持HTTP/HTTPS,支持GET/POST)function http_request($url, $data = null)

{    $curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);    if (!empty($data)){

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

}

curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);    $output = curl_exec($curl);

curl_close($curl);    return $output;

}

2. 接收post数据

logger('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].(empty($_SERVER['QUERY_STRING'])?"":("?".$_SERVER['QUERY_STRING'])));

logger($postStr);foreach ($_GET as $key=>$value)

{

logger("_GET: Key: $key; Value: $value");

}foreach ($_POST as $key=>$value)

{

logger("_POST: Key: $key; Value: $value");

}//日志记录function logger($log_content)

{    $max_size = 100000;    $log_filename = "raw.log";    if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}    file_put_contents($log_filename, date('H:i:s')." ".$log_content."\r\n", FILE_APPEND);

}$arr = array(

'code' => 0,

'errMsg' => 'OK',

// 'member' =>array(

// array(

// 'name' => '李逍遥',

// 'gender' => '男'

// ),

// array(

// 'name' => '赵灵儿',

// 'gender' => '女'

// )

// )  );

echo json_encode($arr);

?>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值