Http+socket Programming Batch Posting

Source: Internet
Author: User

<?php

//
interfaces for HTTP request ClassesInterfaceProto {//Connection URLfunction conn ($url); //send a Get queryfunctionGet(); //Send post Queryfunction post (); //Close Connectionfunction Close ();}classHttp implements Proto {ConstCRLF ="\ r \ n"; protected$errno =-1; protected$errstr ="'; protected$response ="'; protected$url =NULL; protected$version ='http/1.1'; protected$FH =NULL; protected$line =Array (); protected$header =Array (); protected$body =Array (); Publicfunction __construct ($url) {$ This-Conn ($url); $ This->setheader ('Host:'. $ This->url['Host']); } //This method is responsible for writing the request line protectedfunction Setline ($method) {$ This->line[0] = $method.' '. $ This->url['Path'] .' '. $ This-version; } //This method is responsible for writing header information protectedfunction SetHeader ($headerline) {$ This->header[] =$headerline; } //This method is responsible for writing the principal information protectedfunction Setbody ($body) {$ This->body[] =http_build_query ($body); } //Connection URL Publicfunction Conn ($url) {$ This->url =Parse_url ($url); //Determine the port if(!isset ($ This->url['Port'])) { $ This->url['Port'] = the; } $ This-&GT;FH = Fsockopen ($ This->url['Host'],$ This->url['Port'],$ This->errno,$ This-&GT;ERRSTR,3); } //constructing data for GET requests PublicfunctionGet() { $ This->setline ('GET'); $ This-request (); return$ This-response; } //constructing data for a post query Publicfunction post ($body =Array ()) { $ This->setline ('POST'); //Design Content-type$ This->setheader ('content-type:application/x-www-form-urlencoded'); //design body information, which is different than get$ This-setbody ($body); //Calculate Content-length$ This->setheader ('content-length:'. Strlen ($ This->body[0])); $ This-request (); } //really request Publicfunction Request () {//Put the request line, header information, entity information in an array, easy to splice$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-&GT;FH,1024x768); } $ This->close ();//Close Connection } //Close Connection Publicfunction 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 (' tit ' = ' + $tit, ' con ' + $con, ' submit ' + ' message '));

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

Usleep (2000);
}

Http+socket Programming Bulk posting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.