php不使用curl发送post请求

    选择打赏方式

5eb8f38688102954.jpg

<?php
/*
发送post请求函数
*/
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' => 60 // 超时时间(单位:s)
      )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}
// 然后把需要post的数据保存为一个数组,调用send_post函数即可
$post_data = array(
    'test1' => '1',
    'test2' => '2'
);
$return = send_post('http://xxx.com/xxx.php', $post_data);

版权声明:若无特殊注明,本文为《傲世》原创,转载请保留文章出处。
本文链接:https://www.recho.cn/149.html
正文到此结束

热门推荐

发表吐槽

匿名评论 请叫我雷锋~

你还可以输入 250 / 250 个字

呵呵 哈哈 吐舌 开心 笑眼 可怜 乖 啊 你懂得 不高兴 生气 汗 黑线 哭 真棒 阴险 鄙视 酷 滑稽 纳尼 疑问 委屈 惊讶 勉强

评论信息框
可使用QQ号实时获取头像自动填写

私密评论

吃奶的力气提交吐槽中...

已有1条吐槽

匿名

2022-02-04 11:12 俄罗斯 CZ88.NET
WOW just what I was searching for. Came here by searching for 阅客网
  Mac OS X 10.10.2    Google Chrome 51.0.2704.84