分享一个HTTPS的用到的PHP POST请求函数

作者:hzcwd | 更新时间:2019-01-23 | 浏览量:1030


 

/*
$url:地址
$param:参数(数组)
 */
function send_post($url, $param) {
  $options = array(
    'http' => array(
      'method' => 'POST',
      'header' => 'Content-type:application/x-www-form-urlencoded',
      'content' => http_build_query($param),
      'timeout' => 5
    )
  );
  $context = stream_context_create($options);
  $result = file_get_contents($url, false, $context);
  return $result;
}


使用方法:

$url = 'https://www.bigiot.net/oauth/token';

$param['grant_type'] = 'password';
$param['client_id'] = '111';
$param['client_secret'] = '1234';
$param['username'] = '123';
$param['password'] = '123';
$rs = send_post($url,$param);


评论:共1条

贝壳物联 评论于:2019-01-24 09:41:59
多谢分享!
返回顶部