Регистрация
Войти
Войти через VK Войти через FB Войти через Google Войти через Яндекс
Войти через VK Войти через FB Войти через Google Войти через Яндекс
Поиск по сайту
PHP Поиск
Наша группа в Telegram для обмена идеями, проектами, мыслями, людьми в сфере ИТ г.Ростова-на-Дону: @it_rostov
HttpRequest::send
(PECL pecl_http >= 0.10.0)
HttpRequest::send — Send request
Описание
public HttpMessage HttpRequest::send ( void )Send the HTTP request.
Замечание:
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.
Возвращаемые значения
Returns the received response as HttpMessage object.
Ошибки
Throws HttpRuntimeException, HttpRequestException, HttpMalformedHeaderException, HttpEncodingException.
Примеры
Пример #1 GET example
$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;
}
Пример #2 POST example
$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;
}
Описание класса httprequest, примеры использования класса httprequest.
Смотрите также:
Описание на ru2.php.net
Описание на php.ru