<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<b><font size="4">Examples</font></b>
<br>
To create your own custom HTTP_Header , HTTP_Connection, custom HTTP_Request classes just extend the base classes
and chain the constructors.Some have already been provided: <br>
<br>HTTP_GET_Request - request for a simple GET
<br>HTTP_POST_Request - request for the POST method (appends Content-Type, Content-Length headers)
<br>HTTP_HEAD_Request - request for the HEAD method
<br>HTTP_BasicAuth_Header - header for basic auth
<br>HTTP_Cookie_Header - header for cookie values
<br>
<br>HTTP_Default_Request - Not implemented but could send all default headers for you and have a specification if proxy server or not!
<br>
<br> If you want to fix a bug or have any custom classes you want listed email: ed_williams@postmaster.co.uk
<br> It would be good to have a connection for HTTPS protocol and fix all the bugs :)
<br>
<br>
<b>Example 1.</b>To GET a file from a web server<br>
<br>
include("class.HttpConnection.inc");
$headers[] = new HTTP_Header("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");<br>
$headers[] = new HTTP_Header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows 95;)");<br>
$headers[] = new HTTP_Header("Host", "www.php.net");<br>
$headers[] = new HTTP_Header("Referer", "");<br>
<br>
$req = new HTTP_Request("GET", "/index.html", "HTTP/1.0", $headers);<br>
$con = new HTTP_Connection("www.php.net");<br>
<br>
$con->Connect(); // open a connection to server<br>
$con->Request($req); // send request <br>
$con->Response($res); // creates a response obj read from server<br>
$con->Close(); // close connection to server<br>
<br>
echo $res->GetEntityBody();// echo entity body from response (file contents)<br>
<br>
<b>Example 2.</b>To GET a file from a web server using custom request obj<br>
<br>
$headers[] = new HTTP_Header("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");<br>
$headers[] = new HTTP_Header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows 95;)");<br>
$headers[] = new HTTP_Header("Host", "www.php.net");<br>
$headers[] = new HTTP_Header("Referer", "");<br>
<br>
$req = new HTTP_GET_Request("/index.html", $headers);<br>
$con = new HTTP_Connection("www.php.net");<br>
<br>
$con->Connect(); // open a connection to server<br>
$con->Request($req); // send request <br>
$con->Response($res); // creates a response obj read from server<br>
$con->Close(); // close connection to server<br>
<br>
echo $res->GetEntityBody();// echo entity body from response (file contents)<br>
<br>
<b>Example 3.</b>To GET a protected file from a web server using custom request obj and custom header objs<br>
<br>
$headers[] = new HTTP_Header("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");<br>
$headers[] = new HTTP_Header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows 95;)");<br>
$headers[] = new HTTP_Header("Host", "www.php.net");<br>
$headers[] = new HTTP_Header("Referer", "");<br>
$headers[] = new HTTP_Cookie_Header(array("avalue"=>"a value", "avalue2"=>" another value")); // just a cookie<br>
$headers[] = new HTTP_BasicAuth_Header("a_username", "a_password");<br>
<br>
$req = new HTTP_GET_Request("/index.html", $headers);<br>
$con = new HTTP_Connection("www.php.net");<br>
<br>
$con->Connect(); // open a connection to server<br>
$con->Request($req); // send request <br>
$con->Response($res); // creates a response obj read from server<br>
$con->Close(); // close connection to server<br>
<br>
echo $res->GetEntityBody();// echo entity body from response (file contents)<br>
<br>
<b>Example 4.</b>To POST a file from a web server using custom request obj<br>
<br>
$headers[] = new HTTP_Header("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");<br>
$headers[] = new HTTP_Header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows 95;)");<br>
$headers[] = new HTTP_Header("Host", "www.php.net");<br>
$headers[] = new HTTP_Header("Referer", "");<br>
<br>
$req = new HTTP_POST_Request("/index.html", array("avalue"=>"a value", "avalue2"=>" another value"), $headers);<br>
$con = new HTTP_Connection("www.php.net");<br>
<br>
$con->Connect(); // open a connection to server<br>
$con->Request($req); // send request <br>
$con->Response($res); // creates a response obj read from server<br>
$con->Close(); // close connection to server<br>
<br>
echo $res->GetEntityBody();// echo entity body from response (file contents)<br>
</body>
</html>
|