PHP发送POST请求的三种方式
来源:互联网 发布:spss syntax 导入数据 编辑:程序博客网 时间:2024/05/24 02:38
PHP发送POST请求的三种方式class Request{ public static function post($url, $post_data = '', $timeout = 5){ $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){ $postdata = http_build_query( $data ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents($url, false, $context); return $result; } public static function post3($host,$path,$query,$others=''){ $post="POST $path HTTP/1.1\r\nHost: $host\r\n"; $post.="Content-type: application/x-www-form-"; $post.="urlencoded\r\n${others}"; $post.="User-Agent: Mozilla 4.0\r\nContent-length: "; $post.=strlen($query)."\r\nConnection: close\r\n\r\n$query"; $h=fsockopen($host,80); fwrite($h,$post); for($a=0,$r='';!$a;){ $b=fread($h,8192); $r.=$b; $a=(($b=='')?1:0); } fclose($h); return $r; }}
阅读全文
1 0
- PHP发送POST请求(三种方式)
- PHP发送POST请求的三种方式
- PHP发送POST请求的三种方式
- PHP发送POST请求的三种方式
- php发送post请求的三种方式
- PHP发送POST请求的三种方式
- PHP发送POST请求的三种方式
- PHP发送POST请求的三种方式
- php 发送请求的三种方式
- 前端发送get和post请求的三种方式
- PHP发送POST请求的三种方式 分别使用curl file_get_content fsocket 来实现post提交数据
- PHP发送POST请求的三种方式 分别使用curl file_get_content fsocket 来实现post提交数据
- php发送post请求的三种方法
- php发送post请求的三种方法
- php发送post请求的三种方法
- 用PHP的 sockopen方式发送POST 或GET请求
- php发送post请求
- PHP发送POST请求
- Eclipse 注释xml 快捷键
- 1854: A ∪ B
- 分针网——每日分享:ECMAScript 6之Set和Map数据结构
- java 判断数据类型和方法
- linux 下面查询sql展示更好看的方式
- PHP发送POST请求的三种方式
- 实现封装在安卓里的html5,跳转到指定activity
- spark--actions算子--saveAsTextFile
- gcc 优化选项 -O1 -O2 -O3 -Os 优先级
- Application Performance Management(APM)
- MySQL索引设计背后的数据结构及算法详解
- 动归————红牌
- 堆排序
- svn版本控制工具的学习