downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<HttpRequest::resetCookiesHttpRequest::setContentType>
Last updated: Thu, 26 Jun 2008

HttpRequest::send

(PECL pecl_http:0.10.0-1.5.5)

HttpRequest::send — Send request

Description

public HttpMessage HttpRequest::send ( void )

Send the HTTP request.

Note: While an exception may be thrown, the transfer could have succeeded at least partially, so you might want to check the return values of various HttpRequest::getResponse*() methods.

Return Values

Returns the received response as HttpMessage object.

Errors/Exceptions

Throws HttpRuntimeException, HttpRequestException, HttpMalformedHeaderException, HttpEncodingException.

Examples

Example #1 GET example

<?php
$r
= new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
  
$r->send();
   if (
$r->getResponseCode() == 200) {
      
file_put_contents('local.rss', $r->getResponseBody());
   }
}
catch (HttpException $ex) {
   echo
$ex;
}
?>

Example #2 POST example

<?php
$r
= new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
try {
   echo
$r->send()->getBody();
}
catch (HttpException $ex) {
   echo
$ex;
}
?>



add a noteadd a note User Contributed Notes
Send request
There are no user contributed notes for this page.




<HttpRequest::resetCookiesHttpRequest::setContentType>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs