当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP_Request2_Response类代码示例

本文整理汇总了PHP中HTTP_Request2_Response的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2_Response类的具体用法?PHP HTTP_Request2_Response怎么用?PHP HTTP_Request2_Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTTP_Request2_Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getResponse

 /**
  * Setup a `\HTTP_Request2_Response` with the given type!
  *
  * @param string $func Type of all: getConnection, getUsers
  * @param string $type 'success' or 'failure'
  *
  * @return \HTTP_Request2_Response
  */
 protected function getResponse($func, $type = 'success')
 {
     $response = new \HTTP_Request2_Response('HTTP/1.1 200');
     $json = file_get_contents(dirname(dirname(dirname(__DIR__))) . '/fixtures/' . $func . '/' . $type . '.json');
     $response->appendBody($json);
     return $response;
 }
开发者ID:easybib,项目名称:services_oneall,代码行数:15,代码来源:OneAllTestCase.php

示例2: Services_Twitter_factory

/**
 * Returns an instance of Services_Twitter.
 *
 * @param string $ep      The endpoint to call (eg. )
 * @param bool   $auth    Whether to authenticate or not
 * @param array  $options An optional options array to pass to the 
 *                        Services_Twitter constructor
 *
 * @return Services_Twitter The twitter instance.
 */
function Services_Twitter_factory($ep, $auth = true, $options = array())
{
    //$options['raw_format'] = true;
    global $config;
    if ($auth) {
        $twitter = new Services_Twitter($config['user'], $config['pass'], $options);
    } else {
        $twitter = new Services_Twitter(null, null, $options);
    }
    if (!$config['live_test']) {
        if ($ep == 'exception1') {
            $resp = new HTTP_Request2_Response('HTTP/1.1 401 Unauthorized', false);
            $resp->appendBody('{"request":"\\/statuses\\/friends_timeline.json", ' . '"error":"Could not authenticate you."}');
        } else {
            if ($ep == 'exception2') {
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
            } else {
                $resp = new HTTP_Request2_Response('HTTP/1.1 200 Success', false);
                $file = dirname(__FILE__) . '/data/' . $ep . '.dat';
                $resp->appendBody(file_get_contents($file));
            }
        }
        $mock = new HTTP_Request2_Adapter_Mock();
        $mock->addResponse($resp);
        $request = $twitter->getRequest()->setAdapter($mock);
    }
    return $twitter;
}
开发者ID:gauthierm,项目名称:Services_Twitter,代码行数:38,代码来源:setup.php

示例3: testGetDataFromBody

 public function testGetDataFromBody()
 {
     $response = new HTTP_Request2_Response('HTTP/1.1 200 OK');
     $response->appendBody('oauth_token=foo&oauth_token_secret=bar');
     $res = new HTTP_OAuth_Consumer_Response($response);
     $this->assertEquals(array('oauth_token' => 'foo', 'oauth_token_secret' => 'bar'), $res->getDataFromBody());
 }
开发者ID:localdisk,项目名称:HTTP_OAuth,代码行数:7,代码来源:ResponseTest.php

示例4: Services_GeoNames_factory

/**
 * Return the Services_GeoNames with either a mock adapter or the real adapter
 * depending whether the SERVICES_GEONAMES_LIVETEST environment variable is set
 * or not.
 *
 * @param string $testname The test name (without extension)
 * @param string $user     Username (optional)
 * @param string $token    Auth token (optional)
 *
 * @return Services_GeoNames
 */
function Services_GeoNames_factory($testname, $user = null, $token = null)
{
    $geo = new Services_GeoNames($user, $token);
    if (!getenv('SERVICES_GEONAMES_LIVETEST')) {
        // test with a mock adapter
        $mock = new HTTP_Request2_Adapter_Mock();
        if ($testname == 'test_other_04') {
            $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
        } else {
            if ($testname == 'test_other_07') {
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
                $mock->addResponse($resp);
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
                $mock->addResponse($resp);
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
            } else {
                $resp = new HTTP_Request2_Response('HTTP/1.1 200 Success', false);
                $file = dirname(__FILE__) . '/data/' . $testname . '.dat';
                $resp->appendBody(file_get_contents($file));
            }
        }
        $mock->addResponse($resp);
        $geo->getRequest()->setAdapter($mock);
    }
    return $geo;
}
开发者ID:Andreas-Schoenefeldt,项目名称:viszerale-therapie.at,代码行数:37,代码来源:setup.php

示例5: testQuery

 /**
  * Tests the returned result of {@link Solr::query()}.
  */
 function testQuery()
 {
     $response = new HTTP_Request2_Response('HTTP/1.0 200 OK');
     $solrResponse = '{"responseHeader":{"status":0,"QTime":0,"params":{"q":"php","qt":"standard","wt":"json"}},"response":{"numFound":1,"start":0,"docs":[{"id":42,"title":"PHP 5"}]}}';
     $response->appendBody($solrResponse);
     $this->httpClientMock->expects($this->once())->method('sendRequest')->with($this->equalTo('/select?qt=standard&wt=json&q=php'))->will($this->returnValue($response));
     $this->assertEquals(SolrSearchResult::parseResponse($solrResponse), $this->solr->query('php'));
 }
开发者ID:usamurai,项目名称:swisolr,代码行数:11,代码来源:SolrQueryCommandTest.php

示例6: shouldRetry

 /**
  * Indicates if there should be a retry or not.
  * 
  * @param integer                 $retryCount The retry count.
  * @param \HTTP_Request2_Response $response   The HTTP response object.
  * 
  * @return boolean
  */
 public function shouldRetry($retryCount, $response)
 {
     if ($retryCount >= $this->_maximumAttempts || array_search($response->getStatus(), $this->_retryableStatusCodes) || is_null($response)) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:rdohms,项目名称:azure-sdk-for-php,代码行数:16,代码来源:ExponentialRetryPolicy.php

示例7: extractLinks

 protected function extractLinks(\HTTP_Request2_Response $res)
 {
     $mimetype = explode(';', $res->getHeader('content-type'))[0];
     if (!isset(static::$supportedTypes[$mimetype])) {
         Log::info("MIME type not supported for crawling: {$mimetype}");
         return array();
     }
     $class = static::$supportedTypes[$mimetype];
     $extractor = new $class();
     return $extractor->extract($res);
 }
开发者ID:cweiske,项目名称:phinde,代码行数:11,代码来源:Crawler.php

示例8: setUp

 public function setUp()
 {
     parent::setUp();
     Yii::configure(Yii::$app, ['components' => ['user' => ['class' => 'yii\\web\\User', 'identityClass' => 'common\\models\\User'], 'p24' => ['class' => \merigold\przelewy24\src\Przelewy24Component::className(), 'merchant_id' => $this->merchant_id, 'pos_id' => $this->merchant_id, 'CRC' => $this->CRC]]]);
     Yii::$container->set('HTTP_Request2', function () {
         $response = new HTTP_Request2_Response("HTTP/1.1 200 OK", true);
         $response->appendBody($this->succesresponse);
         $mockAdapter = new HTTP_Request2_Adapter_Mock();
         $mockAdapter->addResponse($response);
         $stub = new HTTP_Request2(\merigold\przelewy24\src\Przelewy24Component::TEST_URL, HTTP_Request2::METHOD_POST);
         $stub->setAdapter($mockAdapter);
         return $stub;
     });
 }
开发者ID:merigold,项目名称:yii2-p24,代码行数:14,代码来源:Przelewy24ComponentTest.php

示例9: getResponse

 /**
  * Send request to OSM server and return the response.
  *
  * @param string $url       URL
  * @param string $method    GET (default)/POST/PUT
  * @param string $user      user (optional for read-only actions)
  * @param string $password  password (optional for read-only actions)
  * @param string $body      body (optional)
  * @param array  $post_data (optional)
  * @param array  $headers   (optional)
  *
  * @access public
  * @return HTTP_Request2_Response
  * @todo   Consider just returning the content?
  * @throws Services_OpenStreetMap_Exception If something unexpected has
  *                                          happened while conversing with
  *                                          the server.
  */
 public function getResponse($url, $method = HTTP_Request2::METHOD_GET, $user = null, $password = null, $body = null, array $post_data = null, array $headers = null)
 {
     $arguments = array($url, $method, $user, $password, $body, implode(":", (array) $post_data), implode(":", (array) $headers));
     $id = md5(implode(":", $arguments));
     $data = $this->cache->get($id);
     if ($data) {
         $response = new HTTP_Request2_Response();
         $response->setStatus(200);
         $response->setBody($data);
         return $response;
     }
     $response = parent::getResponse($url, $method, $user, $password, $body, $post_data, $headers);
     $this->cache->save($id, $response->getBody());
     return $response;
 }
开发者ID:AndrOrt,项目名称:Services_Openstreetmap,代码行数:33,代码来源:HTTPCached.php

示例10: __construct

 /**
  * Constructor.
  *
  * @param string|HTTP_Request $messageOrResponse a string (UTF-8) describing
  *                                               the error, or the
  *                                               HTTP_Request2_Response that
  *                                               caused the exception.
  * @param int                 $code              the error code.
  */
 public function __construct($messageOrResponse, $code = 0)
 {
     $message = false;
     if ($messageOrResponse instanceof HTTP_Request2_Response) {
         $this->response = $messageOrResponse;
         $contentType = $this->response->getHeader('content-type');
         if ($contentType == 'application/xml' && $this->response->getBody()) {
             $prevUseInternalErrors = libxml_use_internal_errors(true);
             $doc = new DOMDocument();
             $ok = $doc->loadXML($this->response->getBody());
             libxml_use_internal_errors($prevUseInternalErrors);
             if ($ok) {
                 $xPath = new DOMXPath($doc);
                 $this->_amazonErrorCode = $xPath->evaluate('string(/Error/Code)');
                 $message = $xPath->evaluate('string(/Error/Message)');
             }
         }
         if (!$message) {
             $message = 'Bad response from server.';
         }
         if (!$code) {
             $code = $this->response->getStatus();
         }
     } else {
         $message = (string) $messageOrResponse;
     }
     parent::__construct($message, $code);
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:37,代码来源:Exception.php

示例11: sendRequest

 /**
  * Returns the next response from the queue built by addResponse()
  *
  * If the queue is empty it will return default empty response with status 400,
  * if an Exception object was added to the queue it will be thrown.
  *
  * @param    HTTP_Request2
  * @return   HTTP_Request2_Response
  * @throws   Exception
  */
 public function sendRequest(HTTP_Request2 $request)
 {
     $environment = base64_encode(serialize($this->buildEnvironment($request)));
     $file = $request->getConfig('index_file');
     $dir = PHPCLIHTTP_FILEPATH_BASE;
     $command = "{$dir}/sendrequest.php {$file} {$environment}";
     exec($command, $output, $return_var);
     if ($return_var !== 0) {
         die("Something went wrong with the request.");
     }
     $output_as_string = trim(implode("\n", $output));
     $output_base64_decoded = base64_decode($output_as_string);
     $output_unserialized = unserialize($output_base64_decoded);
     $response = new HTTP_Request2_Response("HTTP/1.1 200 OK\r\n");
     $response->appendBody($output_unserialized['html']);
     return $response;
 }
开发者ID:runekaagaard,项目名称:php-cli-http,代码行数:27,代码来源:CliAdapter.php

示例12: testShouldFailGracefullyOnFailedTransaction

 public function testShouldFailGracefullyOnFailedTransaction()
 {
     $response = new HTTP_Request2_Response('HTTP/1.1 200 OK');
     $response->appendBody(file_get_contents(dirname(__FILE__) . '/data/AuthorizeNet/error.html'));
     $mock = new HTTP_Request2_Adapter_Mock();
     $mock->addResponse($response);
     $request = new HTTP_Request2();
     $request->setAdapter($mock);
     $object = Payment_Process2::factory('AuthorizeNet');
     $object->login = 'unit';
     $object->password = 'test';
     $object->amount = 1;
     $object->action = Payment_Process2::ACTION_NORMAL;
     $object->setRequest($request);
     $object->setPayment($this->aValidPayment());
     $result = $object->process();
     $this->assertTrue($result instanceof PEAR_Error);
 }
开发者ID:pear,项目名称:payment_process2,代码行数:18,代码来源:Payment_Process2_AuthorizeNetTest.php

示例13: callbackWriteBody

 /**
  * Callback function called by cURL for saving the response body
  *
  * @param    resource    cURL handle (not used)
  * @param    string      part of the response body
  * @return   integer     number of bytes saved
  * @see      HTTP_Request2_Response::appendBody()
  */
 protected function callbackWriteBody($ch, $string)
 {
     // cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
     // response doesn't start with proper HTTP status line (see bug #15716)
     if (empty($this->response)) {
         throw new HTTP_Request2_MessageException("Malformed response: {$string}", HTTP_Request2_Exception::MALFORMED_RESPONSE);
     }
     if ($this->request->getConfig('store_body')) {
         $this->response->appendBody($string);
     }
     $this->request->setLastEvent('receivedBodyPart', $string);
     return strlen($string);
 }
开发者ID:venamax,项目名称:trixandtrax-cl,代码行数:21,代码来源:Curl.php

示例14: extract

 public function extract(\HTTP_Request2_Response $res)
 {
     $url = $res->getEffectiveUrl();
     $base = new \Net_URL2($url);
     $sx = simplexml_load_string($res->getBody());
     $linkInfos = array();
     $alreadySeen = array();
     foreach ($sx->entry as $entry) {
         $linkTitle = (string) $entry->title;
         foreach ($entry->link as $xlink) {
             $linkUrl = (string) $base->resolve((string) $xlink['href']);
             if (isset($alreadySeen[$linkUrl])) {
                 continue;
             }
             if ($xlink['rel'] == 'alternate') {
                 $linkInfos[] = new LinkInfo($linkUrl, $linkTitle, $url);
             }
             $alreadySeen[$linkUrl] = true;
         }
     }
     return $linkInfos;
 }
开发者ID:cweiske,项目名称:phinde,代码行数:22,代码来源:Atom.php

示例15: __construct

 /**
  * Constructor
  *
  * @param string                                         $content Http response
  * as string
  *
  * @param WindowsAzure\Common\Internal\Http\BatchRequest $request Source batch
  * request object
  */
 public function __construct($content, $request = null)
 {
     $params['include_bodies'] = true;
     $params['input'] = $content;
     $mimeDecoder = new \Mail_mimeDecode($content);
     $structure = $mimeDecoder->decode($params);
     $parts = $structure->parts;
     $this->_contexts = array();
     $requestContexts = null;
     if ($request != null) {
         Validate::isA($request, 'WindowsAzure\\Common\\Internal\\Http\\BatchRequest', 'request');
         $requestContexts = $request->getContexts();
     }
     $i = 0;
     foreach ($parts as $part) {
         if (!empty($part->body)) {
             $headerEndPos = strpos($part->body, "\r\n\r\n");
             $header = substr($part->body, 0, $headerEndPos);
             $body = substr($part->body, $headerEndPos + 4);
             $headerStrings = explode("\r\n", $header);
             $response = new \HTTP_Request2_Response(array_shift($headerStrings));
             foreach ($headerStrings as $headerString) {
                 $response->parseHeaderLine($headerString);
             }
             $response->appendBody($body);
             $this->_contexts[] = $response;
             if (is_array($requestContexts)) {
                 $expectedCodes = $requestContexts[$i]->getStatusCodes();
                 $statusCode = $response->getStatus();
                 if (!in_array($statusCode, $expectedCodes)) {
                     $reason = $response->getReasonPhrase();
                     throw new ServiceException($statusCode, $reason, $body);
                 }
             }
             $i++;
         }
     }
 }
开发者ID:GameWisp,项目名称:azure-sdk-for-php,代码行数:47,代码来源:BatchResponse.php


注:本文中的HTTP_Request2_Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。