<?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);
}

 

03 http+socket编程批量发帖的更多相关文章

  1. HTTP 笔记与总结(4 )socket 编程:批量发帖

    浏览器发送 POST 请求: 表单 form.html <!doctype html> <html lang="en"> <head> < ...

  2. HTTP 笔记与总结(5)socket 编程:使用 HTTP 协议模拟登录并发帖

    在 VeryCD 上注册两个帐号,发送和接收站内信,观察 POST 请求时发送的参数(h****2 发送给 d***2).(最好用 FireFox 的 FireBug 工具,发送站内信之前选中 “保持 ...

  3. python网络编程-socket编程

     一.服务端和客户端 BS架构 (腾讯通软件:server+client) CS架构 (web网站) C/S架构与socket的关系: 我们学习socket就是为了完成C/S架构的开发 二.OSI七层 ...

  4. PHP socket编程需要了解的一些基本知识

    前面讲到了 fsockopen 的各种情况,其中涉及了很多其它知识,比如chunked分段传输,Keep-Alive,HTTP头字段等额外的知识,如果对这些知识一知半解,会影响对 PHP 的 sock ...

  5. winsock教程- windows下的socket编程(c语言实现)

    winsock教程- windows下的socket编程(c语言实现) 使用winsock进行socket 编程     这是一个学习windows下socket编程(c语言)的快速指南.这是因为一下 ...

  6. 转:Python 的 Socket 编程教程

    这是用来快速学习 Python Socket 套接字编程的指南和教程.Python 的 Socket 编程跟 C 语言很像. Python 官方关于 Socket 的函数请看 http://docs. ...

  7. Python之路,Day8 - Socket编程进阶

    Python之路,Day8 - Socket编程进阶   本节内容: Socket语法及相关 SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台 ...

  8. Day8 - Python网络编程 Socket编程

    Python之路,Day8 - Socket编程进阶   本节内容: Socket语法及相关 SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台 ...

  9. Android应用开发提高篇(4)-----Socket编程(多线程、双向通信)

    链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/04/2379628.html 一.概述 关于Socket编程的基本方法在基础篇里已经讲过,今天把 ...

随机推荐

  1. 解决 Could not load hsdis-amd64.dll

    win10下想查看JIT编译的汇编源码 结果提示: Could not load hsdis-amd64.dll; library not loadable; PrintAssembly is dis ...

  2. PHP中的验证码类(验证码功能设计之二)

    运行结果: <!--vcode.class.php内容--> <?php class Vcode { private $width; //宽 private $height; //高 ...

  3. 【CF675C】Money Transfers(离散化,贪心)

    http://www.cnblogs.com/chengsheng/p/5535316.html 题目大意:给你n个银行中的存款(负值表示借贷),是成环的,1跟n相接,这n个数的和为0.可以从i向i的 ...

  4. linux内核中打印栈回溯信息 - dump_stack()函数分析【转】

    转自:http://blog.csdn.net/jasonchen_gbd/article/details/45585133 版权声明:本文为博主原创文章,转载请附上原博链接.   目录(?)[-] ...

  5. declaration specifier, declarator, type specifier

    static struct abc * b; static struct abc : declaration specifier * b : declarator struct abc : type ...

  6. AC日记——[HAOI2015]树上操作 洛谷 P3178

    题目描述 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种:操作 1 :把某个节点 x 的点权增加 a .操作 2 :把某个节点 x 为根的子树中所有点的点权都增加 ...

  7. Linux VFS

    翻译自Linux文档中的vfs.txt 介绍 VFS(Virtual File System)是内核提供的文件系统抽象层,其提供了文件系统的操作接口,可以隐藏底层不同文件系统的实现. Directir ...

  8. 洛谷1967货车运输 即 NOIP2013 DAY1 T3

    题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重的情况下,最多 ...

  9. BT种子文件文件结构分析(转)

    估计80%以上接触互联网的人都知道bt是什么东西,任何一个用bt下载的人都知道这样一个概念,种子.bt种子就是记录了p2p对等网络中tracker, nodes, files等信息,也就是说,这个种子 ...

  10. System.Length 函数

    function _PCharLen(P: _PAnsiChr): Longint;{$IFNDEF LEGACY_PCHARLEN}begin  Result := 0;  if P <> ...