<?PHPrequire ('./http.class.php'); $http=NewHttp ('http://home.verycd.com/cp.php?ac=pm&op=send&touid=0&pmid=0'); $http->setheader ('accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); $http->setheader ('Accept-encoding:gzip, deflate'); $http->setheader ('accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3'); $http->setheader ('connection:keep-alive'); $http->setheader ('cookie:hm_lvt_c7849bb40e146a37d411700cb7696e46=1371132935,1371551596,1371552570; Cnzzdata1479=cnzz_eid%3d2070887527-1371133011-http%253a%252f%252fhome.verycd.com%26ntime%3d1371559611%26cnzz_a %3d27%26retime%3d1371559611556%26sin%3dhttp%253a%252f%252fwww.verycd.com%252fi%252f17907141%252f%26ltime% 3D1371559611556%26RTIME%3D1; __utma=248211998.1671623420.1371133015.1371557486.1371559612.4; __utmz=248211998.1371552579.2.2.utmcsr=verycd.com|utmccn= (referral) |utmcmd=referral|utmcct=/; hm_lpvt_c7849bb40e146a37d411700cb7696e46=1371554752; Post_action=repost; baidu_clb_refer=http%3a%2f%2fcwebmail.mail.163.com%2fjs5%2fread%2freadhtml.jsp%3fssid% 3di7zqecycxldkhplnxyxqm9sne5eph1drypvn26nzekk%253d%26mid%3d45%3a1tbilrfahfefolvtcaaass%26color%3d003399% 26PREVENTSETREAD%3DON%26FONT%3D15; Uchome_loginuser=http%e5%8d%8f%e8%ae%ae; UCHOME__REFER=%2FSPACE.PHP%3FDO%3DPM%26FILTER%3DNEWPM; __utmc=248211998; sid=9a48b201fb4d176a7188ef2a3560789651eb4766; member_id=17822047; Member_name=http%e5%8d%8f%e8%ae%ae; mgroupid=93; PASS_HASH=E75F942862A5E927A2FAFFD2D2D582C9; Rememberme=false; uchome_auth=4128oujwyonkcxzvxm4sdrjcugsmt3l0r197pq%2bpdf8fcljsuinzkbxjg0hyupzsrk3xes2furn1ph2cefbnc1h0im7x5a; uchome_sendmail=1; Uchome_checkpm=1; __utmb=248211998.1.10.1371559612; Dcm=1'); $http->setheader ('referer:http://home.verycd.com/cp.php?ac=pm'); $http->setheader ('user-agent:mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) gecko/20100101 firefox/21.0'); $msg=Array ('Formhash'='4f23e777','message'='I'm not watering, please release.','Pmsubmit'='true','pmsubmit_btn'='Send','refer'='http://home.verycd.com/space.php?do=pm&filter=privatepm','username'='HTTP Receive'); File_put_contents ('./res.html', $httppost ($msg)); Echo'OK';
<?PHP/*php+socket Programming Send HTTP request can simulate download, register, login, bulk post*///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->url['Query'] .' '. $ This-version; } //This method is responsible for writing header information Publicfunction 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; } //Judging Query if(!isset ($ This->url['Query'])) { $ This->url['Query'] ="'; } $ This->FH = Fsockopen ($ This->url['Host'],$ This->url['Port'],$ This->errno,$ This->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 (); return$ This-response; } //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->FH,1024x768); } $ This->close ();//Close Connection } //Close Connection Publicfunction Close () {fclose ($ This-FH); } }
HTTP protocol Simulation Landing post