src/net/http/CurlHttpClient.php
public function send(HttpRequest $request) {
        if (!is_resource($this->hCurl))
            $this->hCurl = curl_init();

        $response = new CurlHttpResponse();
        $options  = $this->prepareCurlOptions($request, $response);

        // CURLOPT_FOLLOWLOCATION funktioniert nur bei deaktiviertem "open_basedir"-Setting
        if (!ini_get('open_basedir')) {
            if ($this->isFollowRedirects()) {
                $options[CURLOPT_FOLLOWLOCATION] = true;
            }
            elseif (isset($options[CURLOPT_FOLLOWLOCATION]) && $options[CURLOPT_FOLLOWLOCATION]) {
                $this->setFollowRedirects(true);
            }
            if ($this->isFollowRedirects()) {
                !isset($options[CURLOPT_MAXREDIRS]) && $options[CURLOPT_MAXREDIRS]=$this->maxRedirects;
            }
        }

        if ($request->getMethod() == 'POST') {
            $options[CURLOPT_POST      ] = true;
            $options[CURLOPT_URL       ] = substr($request->getUrl(), 0, strpos($request->getUrl(), '?'));
            $options[CURLOPT_POSTFIELDS] = strstr($request->getUrl(), '?');
        }
        curl_setopt_array($this->hCurl, $options);

        // Request ausfuehren
        if (curl_exec($this->hCurl) === false) throw new IOException('cURL error '.self::getError($this->hCurl).','.NL.'URL: '.$request->getUrl());
        $status = curl_getinfo($this->hCurl, CURLINFO_HTTP_CODE);
        $response->setStatus($status);

        // ggf. manuellen Redirect ausfuehren (falls "open_basedir" aktiviert ist)
        if (($status==301 || $status==302) && $this->isFollowRedirects() && ini_get('open_basedir')) {
            if ($this->manualRedirects >= $this->maxRedirects) throw new IOException('CURL error: maxRedirects limit exceeded - '.$this->maxRedirects.', URL: '.$request->getUrl());
            $this->manualRedirects++;

            /** @var string $location */
            $location = $response->getHeader('Location');                       // TODO: relative Redirects abfangen
            Logger::log('Performing manual redirect to: '.$location, L_INFO);   // TODO: verschachtelte IOExceptions abfangen
            $request  = new HttpRequest($location);
            $response = $this->send($request);
        }

        return $response;
    }
public function send(HttpRequest $request) {
        if (!is_resource($this->hCurl))
            $this->hCurl = curl_init();

        $response = new CurlHttpResponse();
        $options  = $this->prepareCurlOptions($request, $response);

        // CURLOPT_FOLLOWLOCATION funktioniert nur bei deaktiviertem "open_basedir"-Setting
        if (!ini_get('open_basedir')) {
            if ($this->isFollowRedirects()) {
                $options[CURLOPT_FOLLOWLOCATION] = true;
            }
            elseif (isset($options[CURLOPT_FOLLOWLOCATION]) && $options[CURLOPT_FOLLOWLOCATION]) {
                $this->setFollowRedirects(true);
            }
            if ($this->isFollowRedirects()) {
                !isset($options[CURLOPT_MAXREDIRS]) && $options[CURLOPT_MAXREDIRS]=$this->maxRedirects;
            }
        }

        if ($request->getMethod() == 'POST') {
            $options[CURLOPT_POST      ] = true;
            $options[CURLOPT_URL       ] = substr($request->getUrl(), 0, strpos($request->getUrl(), '?'));
            $options[CURLOPT_POSTFIELDS] = strstr($request->getUrl(), '?');
        }
        curl_setopt_array($this->hCurl, $options);

        // Request ausfuehren
        if (curl_exec($this->hCurl) === false) throw new IOException('cURL error '.self::getError($this->hCurl).','.NL.'URL: '.$request->getUrl());
        $status = curl_getinfo($this->hCurl, CURLINFO_HTTP_CODE);
        $response->setStatus($status);

        // ggf. manuellen Redirect ausfuehren (falls "open_basedir" aktiviert ist)
        if (($status==301 || $status==302) && $this->isFollowRedirects() && ini_get('open_basedir')) {
            if ($this->manualRedirects >= $this->maxRedirects) throw new IOException('CURL error: maxRedirects limit exceeded - '.$this->maxRedirects.', URL: '.$request->getUrl());
            $this->manualRedirects++;

            /** @var string $location */
            $location = $response->getHeader('Location');                       // TODO: relative Redirects abfangen
            Logger::log('Performing manual redirect to: '.$location, L_INFO);   // TODO: verschachtelte IOExceptions abfangen
            $request  = new HttpRequest($location);
            $response = $this->send($request);
        }

        return $response;
    }
public function send ( HttpRequest $ request ) { if ( ! is_resource ( $ this -> hCurl ) ) $ this -> hCurl = curl_init ( ) ; $ response = new CurlHttpResponse ( ) ; $ options = $ this -> prepareCurlOptions ( $ request , $ response ) ; // CURLOPT_FOLLOWLOCATION funktioniert nur bei deaktiviertem "open_basedir"-Setting if ( ! ini_get ( 'open_basedir' ) ) { if ( $ this -> isFollowRedirects ( ) ) { $ options [ CURLOPT_FOLLOWLOCATION ] = true ; } elseif ( isset ( $ options [ CURLOPT_FOLLOWLOCATION ] ) && $ options [ CURLOPT_FOLLOWLOCATION ] ) { $ this -> setFollowRedirects ( true ) ; } if ( $ this -> isFollowRedirects ( ) ) { ! isset ( $ options [ CURLOPT_MAXREDIRS ] ) && $ options [ CURLOPT_MAXREDIRS ] = $ this -> maxRedirects ; } } if ( $ request -> getMethod ( ) == 'POST' ) { $ options [ CURLOPT_POST ] = true ; $ options [ CURLOPT_URL ] = substr ( $ request -> getUrl ( ) , 0 , strpos ( $ request -> getUrl ( ) , '?' ) ) ; $ options [ CURLOPT_POSTFIELDS ] = strstr ( $ request -> getUrl ( ) , '?' ) ; } curl_setopt_array ( $ this -> hCurl , $ options ) ; // Request ausfuehren if ( curl_exec ( $ this -> hCurl ) === false ) throw new IOException ( 'cURL error ' . self :: getError ( $ this -> hCurl ) . ',' . NL . 'URL: ' . $ request -> getUrl ( ) ) ; $ status = curl_getinfo ( $ this -> hCurl , CURLINFO_HTTP_CODE ) ; $ response -> setStatus ( $ status ) ; // ggf. manuellen Redirect ausfuehren (falls "open_basedir" aktiviert ist) if ( ( $ status == 301 || $ status == 302 ) && $ this -> isFollowRedirects ( ) && ini_get ( 'open_basedir' ) ) { if ( $ this -> manualRedirects >= $ this -> maxRedirects ) throw new IOException ( 'CURL error: maxRedirects limit exceeded - ' . $ this -> maxRedirects . ', URL: ' . $ request -> getUrl ( ) ) ; $ this -> manualRedirects ++ ; /** @var string $location */ $ location = $ response -> getHeader ( 'Location' ) ; // TODO: relative Redirects abfangen Logger :: log ( 'Performing manual redirect to: ' . $ location , L_INFO ) ; // TODO: verschachtelte IOExceptions abfangen $ request = new HttpRequest ( $ location ) ; $ response = $ this -> send ( $ request ) ; } return $ response ; }
Fuehrt den uebergebenen Request aus und gibt die empfangene Antwort zurueck.

@param  HttpRequest $request

@return HttpResponse

@throws IOException wenn ein Fehler auftritt
Fuehrt den uebergebenen Request aus und gibt die empfangene Antwort zurueck .