HTTP in PHP PEAR HTTP related packagepear can implement HTTP operations such as remote page capture, judgment page, Socket operation, simulation authentication, commit, upload, download file, etc. related to HTTP operations, in this zero fragmentation Some of the code, used after preparation, no finishing.
HTTP_REQUEST crashes remote page PhpRequire_once "http / request.php"; // A page $ req = & new http_request ("http://www.b2c-battery.co.uk/"); if (! Pear: : iSerror ($ req-> sendrequest ()) {Echo $ req-> getResponsebody ();} // Second page $ req-> setMethod (http_request_method_post); // http_request_method_get $ req-> addpostdata ("foo" , "bar"); $ req-> seturl ("http://pear.php.net"); $ req-> clearpostdata (); if (! Pear :: ISERROR ($ req-> sendrequest ()))) {$ Response2 = $ req-> getResponsebody ();} else {$ response2 = "} Echo $ response2;?> // Get an identity authentication page (Authentication verification mode) PhpRequire_once" http / request.php " $ REQ = & new http_request ("http://www.examples.com/protected); $ Req-> SetBasicAuth (" 111 "," 111 ");
$ response = $ req-> sendrequest ();
IF (Pear :: ISERROR ($ response)) {Echo $ response-> getMessage ();} else {echo $ req-> getResponsebody ();}?> // detect if a specified URL is available
phpRequire_once "http / request.php";
$ urls = array ("http://www.example.com/", "http://example.com/thisdoesnotexist.html");
$ REQ = & new http_request (""); Foreach ($ URLS AS $ URL) {$ Req-> Seturl ($ URL); $ REQ-> SendRequest ();
$ code = $ req-> getResponsecode (); switch ($ code) {copy 404: echo "document not found / n";
Case 200: Echo "Everything's OK / N"; BREAK;
/ * ... * /}}?>
// Download common file types are: Application / PDF Application / Zip Application / X-OCTSTREAM / / / Default TEXT / CSS IMAGE / JPEG, etc. PhpRequire_once 'pear.php'; Require_once 'http / download.php'; PEAR :: SETERRORHANDLING (Pear_error_print); // $ params = @ $ _ get ['params']; $ _ get ['op'] = 'send'; $ _ get ['what'] = 'file'; switch ($ _Get [ 'what']) {CASE 'File': $ Params ['file'] = 'phpbb.tar.gz'; Break; Case 'Resource': $ params ['resource'] = fopen ('data.txt', 'RB'); Break; Case 'Data': $ Params ['Data'] = file_get_contents ('Data.txt'); Break;} Switch ($ _GET ['OP']) {CASE 'Static': http_download: : Staticsend; Break; Case 'Send': $ h = & new http_download; // Download with this setting // $ params ['contenttype'] = ... // $ h-> setParams ($ Params); $ h-> send (); break; case 'arch': http_download :: Sendarchive ('foo.'] $ _get ['type'], $ _get ['what'], $ _get ['type' ]);