<?php

// http请求类的接口
interface Proto {
// 连接url
function conn($url); //发送get查询
function get(); // 发送post查询
function post(); // 关闭连接
function close();
} class Http implements Proto { const CRLF = "\r\n"; protected $errno = -;
protected $errstr = '';
protected $response = ''; protected $url = null;
protected $version = 'HTTP/1.1';
protected $fh = null; protected $line = array();
protected $header = array();
protected $body = array(); public function __construct($url) {
$this->conn($url);
$this->setHeader('Host: ' . $this->url['host']);
} // 此方法负责写请求行
protected function setLine($method) {
$this->line[] = $method . ' ' . $this->url['path'] . ' '. $this->version;
} // 此方法负责写头信息
protected function setHeader($headerline) {
$this->header[] = $headerline;
} // 此方法负责写主体信息
protected function setBody($body) {
$this->body[] = http_build_query($body);
} // 连接url
public function conn($url) {
$this->url = parse_url($url);
// 判断端口
if(!isset($this->url['port'])) {
$this->url['port'] = ;
} $this->fh = fsockopen($this->url['host'],$this->url['port'],$this->errno,$this->errstr,);
} //构造get请求的数据
public function get() {
$this->setLine('GET');
$this->request();
return $this->response;
} // 构造post查询的数据
public function post($body = array()) {
$this->setLine('POST'); // 设计content-type
$this->setHeader('Content-type: application/x-www-form-urlencoded'); // 设计主体信息,比GET不一样的地方
$this->setBody($body); // 计算content-length
$this->setHeader('Content-length: ' . strlen($this->body[])); $this->request();
} // 真正请求
public function request() {
// 把请求行,头信息,实体信息 放在一个数组里,便于拼接
$req = array_merge($this->line,$this->header,array(''),$this->body,array(''));
//print_r($req); $req = implode(self::CRLF,$req);
//echo $req; exit; fwrite($this->fh,$req); while(!feof($this->fh)) {
$this->response .= fread($this->fh,);
} $this->close(); // 关闭连接
} // 关闭连接
public function close() {
fclose($this->fh);
} }

set_time_limit(0);


$url = 'http://xxxxx.net.cn/0523/?';



for($i=1;$i<100;$i++) {
$str = str_shuffle('abcdefghijklmnopqrst0776656');
$tit = substr($str,0,5);
$con = substr($str,6,8);


$http = new Http($url);
$http->post(array('tit'=>$tit,'con'=>$con,'submit'=>'留言'));


echo $tit,'-----------',$con,'<br />';


usleep(2000);
}

 

最新文章

  1. 【.net 深呼吸】细说CodeDom(4):类型定义
  2. 程序中使用ajax时,type为put,或者delete时在 IIS上没效果,发生HTTP Error 405.0 - Method Not Allowed
  3. [AnuglarJS] TweenMax with ngAnimate
  4. js 获取 当前时间 时间差 时间戳 倒计时
  5. java中的url 编码与解码
  6. yarn源代码
  7. Android 打造炫目的圆形菜单 秒秒钟高仿建行圆形菜单
  8. [每日一题] 11gOCP 1z0-052 :2013-09-15 Enterprise Manager Support Workbench..................B9
  9. MEF实现设计上的“松耦合”
  10. 【安装】python3.4版安装与2.x共存问题
  11. Object-C定时器,封装GCD定时器的必要性!!! (二)
  12. MSB4064 错误
  13. 无外接键盘安装 raspberry pi 3B+ 安装系统
  14. Visual Studio连接到TFS
  15. Ubuntu14.04 安装MySQL 及Can‘t connect to local MYSQL server through socket ’/var/run/mysqld/mysqld.sock‘ (2)
  16. vue-cli 项目搭建
  17. 在简历中使用STAR法则
  18. sencha touch 实现安卓toast效果(2013-9-26)
  19. SQL——ROW_NUMBER
  20. Go语言2

热门文章

  1. log4j.xml——java日志处理组件配置简介
  2. el-select绑定值为对象时,报错[Vue warn]: &lt;transition-group&gt; children must be keyed: &lt;ElTag&gt;
  3. 使用UE配置Python编程环境
  4. Atcoder CODE FESTIVAL 2017 qual B E - Popping Balls 组合计数
  5. 部分转 php kafka
  6. w3school JavaScript 简介
  7. Office文件上传自动生成缩略图-C#开发
  8. iOS内购总结
  9. SYN攻击SYN Attack
  10. gitlab详解