当前位置: 首页 > news >正文

seo网站优化网站制作价格推 荐

seo网站优化,网站制作价格推 荐,站酷网怎么样,wordpress哪种主题好本文介绍一个php实现的http请求封装类#xff0c;封装了三种post提交方法和一个request请求方法#xff0c;并提供了调用示例#xff0c;供大家学习参考。在php编程调试时#xff0c;经常需要模拟提交。另外#xff0c;在抓取一些页面时#xff0c;需要经常请求别人的页面…本文介绍一个php实现的http请求封装类封装了三种post提交方法和一个request请求方法并提供了调用示例供大家学习参考。在php编程调试时经常需要模拟提交。另外在抓取一些页面时需要经常请求别人的页面。于是实现了一个http请求的封装类以方便调用。本http请求类封装了三种post提交方法和一个request请求方法。1http请求封闭类0){$this-init($params);}}// -----------------------/*** 参数初始化** param array $params*/public function init($params){if(count($params) 0){foreach($params as $key $val){if(isset($this-$key)){$this-$key $val;}}}}// -----------------------/*** 提交请求** param string $url 请求地址* param mixed $data 提交的数据* param string $type 提交类型curl,socket,stream可选*/public function post($url, $data, $type socket){if(!in_array($type, $this-post_type_list)){die(undefined post type);}$function_name $type . Post;return call_user_func_array(array($this, $function_name), array($url, $data));}// -----------------------/*** 更改默认的ua信息** 本方法常用于模拟各种浏览器** param string $ua_string UA字符串*/public function setUA($user_agent){$this-ua_string $user_agent;return $this;}// -----------------------/*** 设置本地cookie文件** 在用curl来模拟时常需要设置此项** param string $cookie_file 文件路径*/public function setCookieFile($cookie_file){$this-cookie_file $cookie_file;return $this;}// -----------------------/*** curl方式提交** param string $url 请求地址* param mixed $data 提交的数据* param string $user_agent 自定义的UA* return mixed*/public function curlPost($url, $data, $user_agent ){if($user_agent ){$user_agent $this-ua_string;}if (!is_array($data)){$data array($data);}$data http_build_query($data);if (!function_exists(curl_init)){die(undefined function curl_init);}$ch curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);$rs curl_exec($ch);curl_close($ch);return $rs;}// -----------------------/*** 套接字提交** param string $url 请求地址* param mixed $data 提交的数据* param string $user_agent 自定义的UA* param int $port 端口* param int $timeout 超时限制* return mixed*/public function socketPost($url, $data, $user_agent , $port 80, $timeout 30){$url_info parse_url($url);$remote_server $url_info[host];$remote_path $url_info[path];$socket fsockopen($remote_server, $port, $errno, $errstr, $timeout);if(!$socket){die($errstr($errno));}if($user_agent ){$user_agent $this-ua_string;}if (!is_array($data)){$data array($data);}$data http_build_query($data);fwrite($socket, POST {$remote_path} HTTP/1.0\r\n);fwrite($socket, User-Agent: {$user_agent}\r\n);fwrite($socket, HOST: {$remote_server}\r\n);fwrite($socket, Content-type: application/x-www-form-urlencoded\r\n);fwrite($socket, Content-length: . strlen($data) . \r\n);fwrite($socket, Accept:*/*\r\n);fwrite($socket, \r\n);fwrite($socket, {$data}\r\n);fwrite($socket, \r\n);$header ;while($str trim(fgets($socket, 4096))){$header . $str;}$data ;while(!feof($socket)){$data . fgets($socket, 4096);}return $data;}// -----------------------/*** 文件流提交** param string $url 提交地址* param string $data 数据* param string $user_agent 自定义的UA* return mixed*/public function streamPost($url, $data, $user_agent ){if($user_agent ){$user_agent $this-ua_string;}if (!is_array($data)){$data array($data);}$data http_build_query($data);$context array(http array(method POST,header Content-type: application/x-www-form-urlencoded. \r\n . User-Agent : . $user_agent . \r\n . Content-length: . strlen($data),content $data));$stream_context stream_context_create($context);$data file_get_contents($url, FALSE, $stream_context);return $data;}// -----------------------/*** 发送请求** 本方法通过curl函数向目标服务器发送请求** param string $url 请求地址* return mixed*/public function request($url){$ch curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_USERAGENT, !empty($this-ua_string)? $this-ua_string : $_SERVER[HTTP_USER_AGENT]);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);if (isset($this-cookie_file)){curl_setopt($ch, CURLOPT_COOKIEJAR, $this-cookie_file);}$data curl_exec($ch);curl_close($ch);return $data;}}?调用示例socket);$rs[] $HttpHelper-post($url, $data);$data array(namecurl);$rs[] $HttpHelper-post($url, $data, curl);$data array(namestream);$rs[] $HttpHelper-post($url, $data, stream);$rs[] $HttpHelper-request($url);print_r($rs);?3post.php文件4输出结果Array([0] test request:Array([name] socket)[1] test request:Array([name] curl)[2] test request:Array([name] stream)[3] test request:Array())
http://www.pierceye.com/news/415233/

相关文章:

  • 产品包装设计素材网站均安建网站
  • 甘肃建设网站找别人做网站需要注意什么
  • php做电子商城网站创业找项目
  • 网站建设建设公司有哪些帝国手机网站cms系统
  • 网站设计包括什么软件房产交易网上预约平台
  • 企业做网站有什么好处坏处四川住房城乡和城乡建设厅网站首页
  • 小学学校网站建设计划广州seo顾问服务
  • 做淘宝素材网站哪个好用网站制作网站建设需要多少钱
  • 住房建设部官方网站设计费计取wordpress仿百度搜索主题
  • 云建站平台哪家好沈阳百度seo关键词排名优化软件
  • 响应式网站设计的优点国内优秀设计网站
  • 网站开发集成环境国内html5网站欣赏
  • iis7.5 没有默认网站北京seo的排名优化
  • 两学一做网站是多少钱营销型网站策划怎么做
  • 渭南做网站的自建房设计图
  • 移动网站建设价格线上推广专员是干嘛的
  • 做化妆刷的外贸网站企业网站托管备案
  • 湖南省建设干部学校 网站金融直播室网站建设
  • 贵州建设厅特殊工种考试网站photoshop平面设计教学视频
  • 怎么推广我的网站代理网站推荐
  • wordpress主题站模板做网站跟做APP哪个容易
  • 杭州网站建设公司推荐网站建设优化服务渠道
  • php是网站开发语言吗做网站前端需要编程基础吗
  • python 网站开发 前端企业信用信息系统官网
  • 公司网站设计有哪些使用技巧呢商城网站建设怎么收费
  • 东莞做网站平台安阳营销型网站建设
  • 如何查看网站开发语言百度排行榜风云榜
  • 泉州 网站建设公司首选广告设计公司名字有寓意有创意
  • 天津个人做网站慈利网站制作
  • 专门做推广的网站吗宿迁房价2023年最新房价