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


PHP Unirest\Request类代码示例

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


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

示例1: send

 public function send(Request $r)
 {
     try {
         Unirest::timeout($this->timeout);
         $http = Unirest::{$r->method}($r->url, $r->headers, $r->body);
         $response = new Response((string) $http->raw_body);
         $response->statusCode = (string) $http->code;
         $response->json = json_decode((string) $response, true);
     } catch (\Exception $e) {
         $response = new Response($e->getMessage());
         $response->statusCode = 500;
     }
     $this->logger->logHttpCommunication($r, $response);
     return $response;
 }
开发者ID:sojki,项目名称:payments-sdk-php,代码行数:15,代码来源:JsonBrowser.php

示例2: fetch

 /**
  * @param string|array $param Options or ID
  * @return \stdClass
  */
 public function fetch($param)
 {
     if (is_string($param)) {
         return new Payment($this->response(Request::get(Endpoints::fetch($param))->raw_body));
     } else {
         $response = json_decode(Request::get(Endpoints::fetch($param))->raw_body, true);
         $json['entity'] = "collection";
         foreach ($response as $key => $item) {
             $json['items'][$key] = new Payment($this->response($item));
         }
         return $this->response($json);
     }
 }
开发者ID:niranjan94,项目名称:razorpay-client,代码行数:17,代码来源:PaymentHandler.php

示例3: __construct

 /**
  * @param \Codecasts\Restinga\Contracts\Data\Resource $resource
  * @param bool                                        $identified
  */
 public function __construct(Resource $resource, $identified = false)
 {
     $this->resource = $resource;
     $this->identified = $identified;
     $this->descriptor = $this->resource->getDescriptor();
     $this->request = new Unirest\Request();
     $this->request = $this->descriptor->authorization()->setupRequest($this->request);
     $this->request->defaultHeader('Content-Type', $this->resource->getContentTypeHeader());
     $this->request->defaultHeader('Accept', $this->resource->getAcceptHeader());
 }
开发者ID:codecasts,项目名称:restinga,代码行数:14,代码来源:Request.php

示例4: performTransaction

 /**
  * [performTransaction description].
  *
  * @return [type] [description]
  */
 protected function performTransaction()
 {
     $this->prepareRequest();
     $unirestResponse = Unirest::post($this->endpoint, array(), $this->requestBody);
     $this->responseXMLString = $unirestResponse->body;
     $this->responseXML = simplexml_load_string($this->responseXMLString);
 }
开发者ID:refo,项目名称:payment,代码行数:12,代码来源:Gateway.php

示例5: sendContent

 public function sendContent($from, $to, $subject, $type, $content)
 {
     if (is_string($to)) {
         $to = [$to];
     }
     $recipients = Mailjet::parse_recipient_type($to);
     // Build the HTTP POST body text
     if ($type == 'html') {
         $body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'html' => $content));
     } else {
         if ($type == 'text') {
             $body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'text' => $content));
         } else {
             throw new Exception('Wrong email type');
         }
     }
     utils::log($body);
     $options = array('scheme' => 'http', 'host' => 'api.mailjet.com', 'path' => '/v3/send/');
     $endpoint = Mailjet::unparse_url($options);
     $headers = array('Authorization' => 'Basic ' . $this->_authentificate, 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Length' => strlen($body));
     // API request
     Unirest\Request::verifyPeer(false);
     $response = Unirest\Request::post($endpoint, $headers, $body);
     utils::log('STATUS: ' . $response->code);
     utils::log('HEADERS: ' . json_encode($response->headers));
     utils::log('BODY: ' . $response->raw_body);
     return $response->code == 200;
 }
开发者ID:cyrillef,项目名称:extract-php-view.and.data.api,代码行数:28,代码来源:mailjet.php

示例6: Form

 public static function Form($data)
 {
     if (is_array($data) || is_object($data) || $data instanceof \Traversable) {
         return http_build_query(Request::buildHTTPCurlQuery($data));
     }
     return $data;
 }
开发者ID:RusinovIG,项目名称:unirest-php,代码行数:7,代码来源:Body.php

示例7: post

 public static function post($body = null, $headers = null)
 {
     if (!$headers) {
         $headers = Rapid::getAuthHeader();
     }
     $response = Request::post(Rapid::getUrl(self::$route), $headers, http_build_query($body));
     return Response::make($response);
 }
开发者ID:radiegtya,项目名称:rapid-api-php,代码行数:8,代码来源:Guestbooks.php

示例8: deleteAll

 public static function deleteAll($headers = null)
 {
     if (!$headers) {
         $headers = Rapid::getAuthHeader();
     }
     $response = Request::delete(Rapid::getUrl(self::$route), $headers);
     return Response::make($response);
 }
开发者ID:radiegtya,项目名称:rapid-api-php,代码行数:8,代码来源:Texts.php

示例9: testHttpBuildQueryWithCurlFile

 public function testHttpBuildQueryWithCurlFile()
 {
     $fixture = __DIR__ . '/fixtures/upload.txt';
     $file = Body::File($fixture);
     $body = array('to' => 'mail@mailinator.com', 'from' => 'mail@mailinator.com', 'file' => $file);
     $result = Request::buildHTTPCurlQuery($body);
     $this->assertEquals($result['file'], $file);
 }
开发者ID:RusinovIG,项目名称:unirest-php,代码行数:8,代码来源:BodyTest.php

示例10: getSubdistrict

 public function getSubdistrict($city_id, $subdistrict_id = NULL)
 {
     $params = is_null($city_id) ? NULL : array('city' => $city_id);
     if (!is_null($subdistrict_id)) {
         $params['id'] = $subdistrict_id;
     }
     return \Unirest\Request::get($this->getEndPoint() . "subdistrict", $this->getHeader(), $params)->body->rajaongkir->results;
 }
开发者ID:huang-tianwen,项目名称:rajaongkir-phpsdk,代码行数:8,代码来源:APIClient.php

示例11: getPlayUrl

 /**
  * 获取播放地址
  * @return array
  */
 public function getPlayUrl()
 {
     $response = \Unirest\Request::get($this->url);
     preg_match('#value=\'(?<url>.*?)\'><a id="v_slink_souce"#', $response->body, $m);
     if (!empty($m['url'])) {
         return ['swf' => trim($m['url'])];
     }
     return false;
 }
开发者ID:baiy,项目名称:video_parse,代码行数:13,代码来源:Video.php

示例12: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     HTTPRequest::verifyPeer(env('UNIREST_VERIFYPEER'));
     //Get 10 quotes, from a Mashape API
     for ($i = 0; $i < 10; $i++) {
         $response = HTTPRequest::post("https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous", array("X-Mashape-Key" => env('MASHAPE_KEY'), "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json"));
         Quote::create(["content" => $response->body->quote, "author" => $response->body->author, "source" => "https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous"]);
     }
 }
开发者ID:marcinlawnik,项目名称:QuoteAggregator,代码行数:14,代码来源:QuotesSeeder.php

示例13: avaliable

 /**
  * Checks if the daemon is running.
  *
  * @param string $ip
  * @param int $port
  * @param int $timeout
  * @return bool
  */
 public function avaliable($ip, $port = 5656, $timeout = 3)
 {
     Unirest\Request::timeout($timeout);
     try {
         Unirest\Request::get("https://" . $ip . ":" . $port);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
开发者ID:PhenixH,项目名称:PufferPanel,代码行数:18,代码来源:daemon.php

示例14: searchContactList

 /**
  * Get list of searched contact list
  * @param  string     $q     Required parameter: Your keyword or query.
  * @return string response from the API call*/
 public function searchContactList($q)
 {
     //check that all required arguments are provided
     if (!isset($q)) {
         throw new \InvalidArgumentException("One or more required arguments were NULL.");
     }
     //the base uri for api requests
     $_queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $_queryBuilder = $_queryBuilder . '/search/contacts-lists';
     //process optional query parameters
     APIHelper::appendUrlWithQueryParameters($_queryBuilder, array('q' => $q));
     //validate and preprocess url
     $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
     //prepare headers
     $_headers = array('user-agent' => 'ClickSendSDK');
     //set HTTP basic auth parameters
     Request::auth(Configuration::$username, Configuration::$key);
     //and invoke the API call request to fetch the response
     $response = Request::get($_queryUrl, $_headers);
     //Error handling using HTTP status codes
     if ($response->code == 400) {
         throw new APIException('BAD_REQUEST', 400, $response->body);
     } else {
         if ($response->code == 401) {
             throw new APIException('UNAUTHORIZED', 401, $response->body);
         } else {
             if ($response->code == 403) {
                 throw new APIException('FORBIDDEN', 403, $response->body);
             } else {
                 if ($response->code == 404) {
                     throw new APIException('NOT_FOUND', 404, $response->body);
                 } else {
                     if ($response->code == 405) {
                         throw new APIException('METHOD_NOT_FOUND', 405, $response->body);
                     } else {
                         if ($response->code == 429) {
                             throw new APIException('TOO_MANY_REQUESTS', 429, $response->body);
                         } else {
                             if ($response->code == 500) {
                                 throw new APIException('INTERNAL_SERVER_ERROR', 500, $response->body);
                             } else {
                                 if ($response->code < 200 || $response->code > 206) {
                                     //[200,206] = HTTP OK
                                     throw new APIException("HTTP Response Not OK", $response->code, $response->body);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $response->body;
 }
开发者ID:clicksend,项目名称:clicksend-php,代码行数:59,代码来源:SearchController.php

示例15: retrieveConfig

 /**
  * A Config object has the following attributes:+ `timezone` - Our sever timezone+ `now` - Our server timestamp+ `version` - Current version is "1.0"+ `serverUrl` - Main API URL+ `photosUrl` - Base Path to server where we store our images+ `productsSorting` - Available Products lists sorting options (can be combined with commas, for example &sort=date,-price )    + `date` - Date ascending    + `-date` - Date descending    + `price` - Price ascending    + `-price` - Price descending    + `distance` - Distance ascending (works only if `latitude`,`longitude` & `distance` parameters are provided, ignored otherwise)     + `-distance` - Distance descending (works only if `latitude`,`longitude` & `distance` parameters are provided, ignored otherwise)+ user - All important userdata for provided API key    + `name` - Name / Company / Organization    + `email` - E-Mail Address    + `uuid` - Unique ID    + `continueUrl` - Continue URL (not in use now)    + `notifyUrl` - Notify URL (not in use now)    + `suggestedMarkup` - Suggested markup, % decimal value, for example 7.5    + `defaultPagination` - Default Pagination value (per page), between 1-100    + `defaultSortBy` - Default sort by for /products (if not specified)    + `defaultCurrencyUuid` - Default currency UUID for /products (if not specified)    + `defaultCurrencyCode` - Default currency code for /products (if not specified)    + `defaultLanguageUuid` - Default language UUID  /products (if not specified)    + `defaultLanguageCode` - Default language code  /products (if not specified)    + `walletBalance` - Partner's available wallet balance, based on his deposits    + `walletAvailableBalance` - Wallet balance which is a combination of partner's deposit and assigned credit amount    + `wallet_alert_value` - Threshold value in SGD, when `walletBallance` reach this value then BMG and partner will be notified on this event+ `languages` - A list of supported languages.+ `currencies` - An array of supported currencies.+ `types` - An array of supported products types.+ `categories` - A tree of supported product categories.+ `locations` - A tree of supported locations. (Continent -> Country -> State -> City)
  * @return mixed response from the API call
  * @throws APIException Thrown if API call fails
  */
 public function retrieveConfig()
 {
     //the base uri for api requests
     $_queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $_queryBuilder = $_queryBuilder . '/v1/config';
     //validate and preprocess url
     $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
     //prepare headers
     $_headers = array('user-agent' => 'BeMyGuest.SDK.v1', 'Accept' => 'application/json', 'X-Authorization' => Configuration::$xAuthorization);
     //call on-before Http callback
     $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
     if ($this->getHttpCallBack() != null) {
         $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
     }
     //and invoke the API call request to fetch the response
     $response = Request::get($_queryUrl, $_headers);
     //call on-after Http callback
     if ($this->getHttpCallBack() != null) {
         $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
         $_httpContext = new HttpContext($_httpRequest, $_httpResponse);
         $this->getHttpCallBack()->callOnAfterRequest($_httpContext);
     }
     //Error handling using HTTP status codes
     if ($response->code == 400) {
         throw new APIException('Wrong Arguments', $_httpContext);
     } else {
         if ($response->code == 401) {
             throw new APIException('Unauthorized', $_httpContext);
         } else {
             if ($response->code == 403) {
                 throw new APIException('Forbidden', $_httpContext);
             } else {
                 if ($response->code == 404) {
                     throw new APIException('Resource Not Found', $_httpContext);
                 } else {
                     if ($response->code == 405) {
                         throw new APIException('Method Not Allowed', $_httpContext);
                     } else {
                         if ($response->code == 410) {
                             throw new APIException('Resource No Longer Available', $_httpContext);
                         } else {
                             if ($response->code < 200 || $response->code > 208) {
                                 //[200,208] = HTTP OK
                                 throw new APIException("HTTP Response Not OK", $_httpContext);
                             }
                         }
                     }
                 }
             }
         }
     }
     $mapper = $this->getJsonMapper();
     return $mapper->map($response->body, new Models\RetrieveConfigResponse());
 }
开发者ID:bemyguest,项目名称:sdk-php,代码行数:60,代码来源:ConfigController.php


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