网站首页
免费技术
源码下载
免费软件
域名空间
活动资讯
值得一看
关于本站
网址导航
您的位置:首页 > 网络技术教程 > 在PHP中发送POST请求
在PHP中发送POST请求
2023-6-12    269    0

PHP发送POST请求
/**
 * 发送post请求
 * @param string $url 请求地址
 * @param array $post_data post键值对数据
 * @return string
 */
function send_post($url, $post_data) { 
  $postdata = http_build_query($post_data);
  $options = array(
    'http' => array(
      'method' => 'POST',
     'header' => 'Content-type:application/x-www-form-urlencoded',
     'content' => $postdata,
      'timeout' => 15 * 60 // 超时时间(单位:s)
    )
  );
  $context = stream_context_create($options);
  $result = file_get_contents($url, false, $context);
  return $result;
}  
//使用方法
$post_data = array(
  'username' => 'admin',
  'password' => 'admin'
);
send_post('http://www.8gws.com', $post_data);
上一篇: 首发价值29800元最新商业版陪玩3.0独立版本系统
下一篇: (自适应手机端)站长网址导航类pbootcms模板 网站目录源码下载