downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

HttpRequest::setContentType> <HttpRequest::resetCookies
Last updated: Fri, 13 Nov 2009

view this page in

HttpRequest::send

(PECL pecl_http >= 0.10.0)

HttpRequest::sendHTTP isteği gönderir

Açıklama

public HttpMessage HttpRequest::send ( void )

HTTP isteği gönderir.

Bilginize: Bir istisna yakalanmışsa, aktarım kısmen de olsa başarılı olmuş demektir. Dolayısıyla, isterseniz, çeşitli HttpRequest::getResponse*() yöntemlerinden dönen değerleri sınayabilirsiniz.

Dönen Değerler

HttpMessage nesnesi olarak alınan yanıtla döner.

Hatalar/İstisnalar

HttpRuntimeException, HttpRequestException, HttpMalformedHeaderException, HttpEncodingException istisnaları yakalanır.

Örnekler

Örnek 1 - GET örneği

<?php
$r 
= new HttpRequest('http://gen.tr/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;
}
?>

Örnek 2 - POST örneği

<?php
$r 
= new HttpRequest('http://gen.tr/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 note add a note User Contributed Notes
HttpRequest::send
mjs at beebo dot org
02-Apr-2009 12:27
Note that send() does not process redirects, and there doesn't appear to any way to get this to happen automatically.  If you need to follow redirects, use something like the following code:

<?php
$request
= new HttpRequest($url, HTTP_METH_GET);
do {
   
$response = $request->send();
    if (
$response->getResponseCode() != 301 && $response->getResponseCode() != 302) break;
   
$request->setUrl($response->getHeader("Location"));
} while (
1);
?>

HttpRequest::setContentType> <HttpRequest::resetCookies
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites