手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

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

时间:2024-10-12 09:21:48

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

2、functio艘绒庳焰n file_get_contents_post($url, $post) { $options = arra烤恤鹇灭y( 'http' => array( 'method' => 'POST', // 'content' => 'name=caiknife&[email protected]', '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就是返回值

© 手抄报圈