如何用PHP实现模拟POST请求的功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计133个文字,预计阅读时间需要1分钟。
phpclass Request { public static function post($url, $post_data='', $timeout=5) { // 初始化curl会话 $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); if ($post_data !='') { curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } // 设置超时时间 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 执行curl会话 $response=curl_exec($ch); // 关闭curl会话 curl_close($ch); return $response; }}
class Request{ public static function post($url, $post_data = '', $timeout = 5){//curl $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, 1); if($post_data != ''){ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HEADER, false); $file_contents = curl_exec($ch); curl_close($ch); return $file_contents; } public static function post2($url, $data=array()){//file_get_content $postdata = ******/con/Inter.php'; $data=Request::post($url,array('api'=>'tag_list')); $data2=Request::post2($url,array('api'=>'tag_list')); echo $data;
本文共计133个文字,预计阅读时间需要1分钟。
phpclass Request { public static function post($url, $post_data='', $timeout=5) { // 初始化curl会话 $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); if ($post_data !='') { curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } // 设置超时时间 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 执行curl会话 $response=curl_exec($ch); // 关闭curl会话 curl_close($ch); return $response; }}
class Request{ public static function post($url, $post_data = '', $timeout = 5){//curl $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, 1); if($post_data != ''){ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HEADER, false); $file_contents = curl_exec($ch); curl_close($ch); return $file_contents; } public static function post2($url, $data=array()){//file_get_content $postdata = ******/con/Inter.php'; $data=Request::post($url,array('api'=>'tag_list')); $data2=Request::post2($url,array('api'=>'tag_list')); echo $data;

