Location: PHPKode > scripts > HTTP Request class > http-request-class/democlass.php
<?php
/*
Author : Martin Fasani [ www.movil.be ]
lastMod: 20050701 [YYYYMMDD]
EXAMPLES of xmlhttpclass implementation
*/
require("classhttpreq.php");

$req1 = new httpreq('req1'); 
$req1->nocache=true;
$req1->httpdorequest('GET','helloworld.txt');
$req1->httpcreate();
/* google search-  
UPDATE: For security reasons now the API key is being replaced at curlproxy.php (You will see @apikey inside the .xml)
Fell free to move the key replacement to any other place but avoid to leave it in any browser accesible page or javascript.

Note that we are not parsing the google response so it will look chunky in the DIV container

   WARNING soapreq.xml: Be aware that if you leave this as is with your key inside, it will be exposed if you publish on the internet. So either add @apikey and then you replace it with the key, or just use it on your own development.
   */
$req2noproxy = new httpreq('req2noproxy'); 
$req2noproxy->send ('soapreq.xml','file'); //data   , [type: file / url / string by default], [cleanwhitespace: true by default]
$req2noproxy->httpdorequest('POST','http://api.google.com/search/beta2');
$req2noproxy->httpcreate();

$req2 = new httpreq('req2'); 
$req2->send ('soapreq.xml','file');
$req2->httpdorequest('POST','proxycurl.php?url=http://api.google.com/search/beta2'); 
$req2->httpfireonload();
$req2->httpcreate();
/* end of google search */

$req3 = new httpreq('req3'); 
$req3->getheader='ALL';  //ALL or name e.g. "Last-Modified"
$req3->httpdorequest('HEAD','helloworld.txt');
$req3->httpcreate();

$req4custom=new httpreq('req4custom'); 
$req4custom->onreadydo="alertmessage('This is a custom JS function')";
//In case you want to use the responseText of the request then you can also:
//$req4custom->onreadydo="alertmessage(req4custom.responseText)"; //The same would aply on a HEAD
$req4custom->httpdorequest('GET','helloworld.txt');
$req4custom->httpcreate();


?>
<script language="javascript">function alertmessage(text) { alert(text) }</script>
<body>Simple open file example:
<div id='req1' style='overflow: auto; width:100%; height: 80px;border:1px solid'>req1</div>
<a href=javascript:httpdoreq1() >httpdoreq1()</a>
<br>
<br>
Client request to remote google SOAP. Remember to add <a href="http://www.google.com/apis" >API key</a> in soapreq.xml
<div id='req2noproxy' style='overflow: auto; width:100%; height: 80px;border:1px solid'>req2noproxy</div>
<a href=javascript:httpdoreq2noproxy() >httpdoreq2noproxy() will work depending on browser the security settings</a>
<br>
<br>
Google SOAP request as local (proxycurl.php). 
<div id='req2' style='overflow: auto; width:100%; height: 80px;border:1px solid'>req2</div>
<a href=javascript:httpdoreq2() >httpdoreq2()</a> fired on onload using httpfireonload()
<br>
<br>
Client HEAD request to local file:
<div id='req3' style='overflow: auto; width:100%; height: 80px;border:1px solid'>req3</div>
<a href=javascript:httpdoreq3() >httpdoreq3()</a> on the file helloworld.txt<br>


<p><a href=javascript:httpdoreq4custom() >httpdoreq4custom()</a> will launch custom function defined in $req4custom->onreadydo </p>
</body>
Return current item: HTTP Request class