HttpRequest class Simple GET request : HttpRequest : Development PHP Source Code


PHP Source Code » Development » HttpRequest »

 

HttpRequest class Simple GET request


The HttpRequest class can be used to execute any HTTP request method. The following example shows a simple GET request where a few query parameters are supplied. Additionally potential cookies will be read from and written to a file.
<?php    
$r 
= new HttpRequest('http://www.google.com/search');    
    
// store Googles cookies in a dedicated file    
touch('google.txt');    
$r->setOptions(    
array( 
'cookiestore' => 'google.txt',    
)    
);    
    
$r->setQueryData(    
array( 
'q' => '+"pecl_http" -msg -cvs -list',    
'hl' => 'de'    
)    
);    
    
// HttpRequest::send() returns an HttpMessage object    
// of type HttpMessage::TYPE_RESPONSE or throws an exception    
try {    
print 
$r->send()->getBody();    
} catch (
HttpException $e) {    
print 
$e;    
}    
?>    


HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Development
» HttpRequest