php进行post提交 并且返回信息

 时间:2026-02-14 15:19:56

1、实现的方法有两种

1、file_get_contents

2、curl_init

2、function file_get_contents_post($url, $post) {

    $options = array(

        'http' => array(

            'method' => 'POST',

            // 'content' => 'name=caiknife&email=caiknife@gmail.com',

            'content' => http_build_query($post),

        ),

    );

    $result = file_get_contents($url, false, stream_context_create($options));

    return $result;

}

3、 function HttpPost($url,$param)//

{

$ch = curl_init(); //初始化curl

curl_setopt($ch, CURLOPT_URL, $url);//设置链接

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置是否返回信息

curl_setopt($ch, CURLOPT_POST, 1);//设置为POST方式

curl_setopt($ch, CURLOPT_POSTFIELDS, $param);//POST数据

$response = curl_exec($ch);//接收返回信息

if(curl_errno($ch)){//出错则显示错误信息

print curl_error($ch);

}

curl_close($ch); //关闭curl链接

return $response;//显示返回信息

}

4、引用

$data = file_get_contents_post("url", array('Id'=>'71529'));

$data = HttpPost("url", array('Id'=>'71529'));

其中

$data就是返回值

  • 微信小游戏脑力吃鸡大作战4-5-6关通关攻略
  • phpstudy如何更改post最大可传输的数据大小
  • 母猪气血充足的重要性
  • 一拳超人:最强之男琦玉天赋如何加点?
  • 荒野行动如何开启平滑自由视角?
  • 热门搜索
    无锡旅游公司 台湾岛旅游网 斯洛伐克旅游 光雾山旅游攻略 惠州 旅游 丽江著名旅游景点 桓仁旅游 国外旅游网站 京津冀旅游年卡 乌海旅游景点大全