• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP HTTP_Request2_Response类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: addCookiesFromResponse

 /**
  * Adds cookies set in HTTP response to the jar
  *
  * @param HTTP_Request2_Response $response HTTP response message
  * @param Net_URL2               $setter   original request URL, needed for
  *                               setting default domain/path
  */
 public function addCookiesFromResponse(HTTP_Request2_Response $response, Net_URL2 $setter)
 {
     foreach ($response->getCookies() as $cookie) {
         $this->store($cookie, $setter);
     }
 }
开发者ID:khanhdeux,项目名称:typo3test,代码行数:13,代码来源:CookieJar.php


示例17: readResponseFromFile

 protected function readResponseFromFile($filename)
 {
     $fp = fopen(dirname(dirname(__FILE__)) . '/_files/' . $filename, 'rb');
     $response = new HTTP_Request2_Response(fgets($fp));
     do {
         $headerLine = fgets($fp);
         $response->parseHeaderLine($headerLine);
     } while ('' != trim($headerLine));
     while (!feof($fp)) {
         $response->appendBody(fread($fp, 1024));
     }
     return $response;
 }
开发者ID:brucewu16899,项目名称:1.6.x,代码行数:13,代码来源:ResponseTest.php


示例18: _return

 /**
  * evaluate response object
  *
  * @param \HTTP_Request2_Response $resp
  *
  * @throws BadRequestError
  * @throws UnauthorizedError
  * @throws ForbiddenError
  * @throws ConflictDuplicateError
  * @throws GoneError
  * @throws InternalServerError
  * @throws NotImplementedError
  * @throws ThrottledError
  * @throws CCException
  *
  * @return string json encoded servers response
  */
 private function _return($resp)
 {
     #
     # And handle the possible responses according to their HTTP STATUS
     # CODES.
     #
     # 200 OK, 201 CREATED and 204 DELETED result in returning the actual
     # response.
     #
     # All non success STATUS CODES raise an exception containing
     # the API error message.
     #
     if (in_array($resp->getStatus(), array(200, 201, 204)) !== false) {
         return $resp->getBody();
     } else {
         if ($resp->getStatus() == 400) {
             throw new BadRequestError($resp->getBody(), $resp->getStatus());
         } else {
             if ($resp->getStatus() == 401) {
                 throw new UnauthorizedError($resp->getBody(), $resp->getStatus());
             } else {
                 if ($resp->getStatus() == 403) {
                     throw new ForbiddenError($resp->getBody(), $resp->getStatus());
                 } else {
                     if ($resp->getStatus() == 409) {
                         throw new ConflictDuplicateError($resp->getBody(), $resp->getStatus());
                     } else {
                         if ($resp->getStatus() == 410) {
                             throw new GoneError($resp->getBody(), $resp->getStatus());
                         } else {
                             if ($resp->getStatus() == 500) {
                                 throw new InternalServerError($resp->getBody(), $resp->getStatus());
                             } else {
                                 if ($resp->getStatus() == 501) {
                                     throw new NotImplementedError($resp->getBody(), $resp->getStatus());
                                 } else {
                                     if ($resp->getStatus() == 503) {
                                         throw new ThrottledError($resp->getBody(), $resp->getStatus());
                                     } else {
                                         throw new CCException($resp->getBody(), $resp->getStatus());
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:cloudcontrol,项目名称:phpcclib,代码行数:67,代码来源:API.php


示例19: getDOMXPath

 /**
  * Returns a DOMXPath object for the XML document in the body of the
  * specified HTTP response. This method is for internal use only.
  *
  * @param HTTP_Request2_Response $response the HTTP response.
  *
  * @return DOMXPath
  * @throws Services_Amazon_S3_ServerErrorException
  */
 public static function getDOMXPath(HTTP_Request2_Response $response)
 {
     if ($response->getHeader('content-type') != 'application/xml') {
         throw new Services_Amazon_S3_ServerErrorException('Response was not of type application/xml', $response);
     }
     $prevUseInternalErrors = libxml_use_internal_errors(true);
     $doc = new DOMDocument();
     $ok = $doc->loadXML($response->getBody());
     libxml_use_internal_errors($prevUseInternalErrors);
     if (!$ok) {
         throw new Services_Amazon_S3_ServerErrorException($response);
     }
     $xPath = new DOMXPath($doc);
     $xPath->registerNamespace('s3', self::NS_S3);
     $xPath->registerNamespace('xsi', self::NS_XSI);
     return $xPath;
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:26,代码来源:S3.php


示例20: parseResponse

 protected function parseResponse(HTTP_Request2_Response $response)
 {
     $this->params = Am_Controller::decodeJson($response->getBody());
 }
开发者ID:alexanderTsig,项目名称:arabic,代码行数:4,代码来源:paymill-dd.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP HWDevice类代码示例发布时间:2022-05-23
下一篇:
PHP HTTP_Request2类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap