博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HTTP socket 类
阅读量:6909 次
发布时间:2019-06-27

本文共 2389 字,大约阅读时间需要 7 分钟。

hot3.png

conn($url); $this->setHeader("Host: ".$this->url['host']); } // 连接 public function conn($url) { $this->url = parse_url($url); if (!isset($this->url['port'])) { $this->url['port'] = '80'; } $this->fh = fsockopen($this->url['host'],$this->url['port'],$this->errno,$this->errstr,$this->expires_time); } // 设置请求行 protected function setLine($method) { $this->url['path'] .= isset($this->url['query']) ? '?'.$this->url['query'] : ''; $this->line[] = $method.' '.$this->url['path'].' '.$this->version; } // 设置头信息 public function setHeader($header) { $this->header[] = $header; } // 设置实体信息 protected function setBody($data) { $this->body[] = http_build_query($data); // $this->body[0] = $data; } // 发送get请求 public function get() { $this->setLine('GET'); $this->request(); return $this->response; } // 发送post查询 public function post($data) { $this->setLine('POST'); $this->setHeader("Content-type: application/x-www-form-urlencoded"); $this->setBody($data); $this->setHeader("Content-length: ".strlen($this->body[0])); $this->request(); return $this->response; } // 真正的请求 protected function request() { $req = array_merge($this->line,$this->header,array(''),$this->body,array('')); $req = implode(self::CRLF,$req); echo $req; // exit; // 写入 fwrite($this->fh,$req); while(!feof($this->fh)){ $this->response .= fread($this->fh,1024); } $this->close(); } // 关闭连接 public function close() { fclose($this->fh); } }// $url = 'http://shunping.com/msg.php';// $url = 'http://news.163.com/13/0613/09/9187CJ4C00014JB6.html';// $http = new Http($url);// echo $http->get();// tit=test&con=tset&submit=%E6%8F%90%E4%BA%A4// $data['tit'] = 'test';// $data['con'] = 'tset';// $data['submit'] = '%E6%8F%90%E4%BA%A4'; // $data['submit'] = '提交';// echo $http->post($data);?>

转载于:https://my.oschina.net/u/946060/blog/284763

你可能感兴趣的文章
linux 安装优化脚本
查看>>
Linux 系统启动过程
查看>>
JAVA知识点随心记
查看>>
一天一点T-SQL:获取每个计划任务的步骤
查看>>
CET免准考证号查分咯
查看>>
Hbuilder内置的svn插件为1.6版的,如何升级为1.8版的?
查看>>
异常处理、模块包、时间模块、subprocess(调用shell命令)
查看>>
我的友情链接
查看>>
Vmware Esxi外接移动硬盘到虚拟机拷贝数据慢
查看>>
ASP.NET MVC 之controller 找不到action 的处理方式
查看>>
利用TC进行流量控制(Qos) 原文:姜道友 著
查看>>
Samba简述
查看>>
人到中年,技术何以糊口
查看>>
错误代码:0x800704cf 不能访问网络位置(win7 访问不了局域网电脑) .
查看>>
Android版SDK与admob管理平台集成教程
查看>>
六、安装laravel5.1
查看>>
华为交换机批量加入 Vlan 方法
查看>>
async 与 await 线程调用顺序
查看>>
马的种类(十四)
查看>>
路由、交换如何Telnet远程配置。
查看>>