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

2025-03-13 06:51:06

1、实现的方法有两种1、file_get_contents2、curl_init

2、function file_get_contents_post($url, $post) { $options = arra烤恤鹇灭y( '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_s髫潋啜缅etopt($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就是返回值

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢