PHP ��U
前一頁 |  | 下一頁

# HttpRequest::send

(no version information, might be only in CVS)

HttpRequest::send -- Send request

## Description

publicHttpMessage 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.

## Return Values

Returns the received response as HttpMessage object.

## Errors/Exceptions

Throws HttpRuntimeException, HttpRequestException, HttpMalformedHeaderException, HttpEncodingException.

## �d��

範例 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; } ?>`

範例 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; } ?>`

前一頁 | 內容 | 下一頁
HttpRequest::resetCookies | 上一層 | HttpRequest::setContentType