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


PHP HttpSocket类代码示例

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


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

示例1: endereco

 function endereco(&$model, $cep)
 {
     if (!$this->_validaCep($cep, '-')) {
         return ERRO_CORREIOS_PARAMETROS_INVALIDOS;
     }
     // Requisição
     $HttpSocket = new HttpSocket();
     $uri = array('scheme' => 'http', 'host' => 'www.correios.com.br', 'port' => 80, 'path' => '/encomendas/prazo/prazo.cfm');
     $data = array('resposta' => 'paginaCorreios', 'servico' => CORREIOS_SEDEX, 'cepOrigem' => $cep, 'cepDestino' => $cep, 'peso' => 1, 'MaoPropria' => 'N', 'valorDeclarado' => 0, 'avisoRecebimento' => 'N', 'Altura' => '', 'Comprimento' => '', 'Diametro' => '', 'Formato' => 1, 'Largura' => '', 'embalagem' => 116600055, 'valorD' => '');
     $retornoCorreios = $HttpSocket->post($uri, $data);
     if ($HttpSocket->response['status']['code'] != 200) {
         return ERRO_CORREIOS_FALHA_COMUNICACAO;
     }
     // Convertendo para o encoding da aplicação. Isto só funciona se a extensão multibyte estiver ativa
     $encoding = Configure::read('App.encoding');
     if (function_exists('mb_convert_encoding') && $encoding != null && strcasecmp($encoding, 'iso-8859-1') != 0) {
         $retornoCorreios = mb_convert_encoding($retornoCorreios, $encoding, 'ISO-8859-1');
     }
     // Checar se o conteúdo está lá e reduzir o escopo de busca dos valores
     if (!preg_match('/\\<b\\>CEP:\\<\\/b\\>(.*)\\<b\\>Prazo de Entrega/', $retornoCorreios, $matches)) {
         return ERRO_CORREIOS_CONTEUDO_INVALIDO;
     }
     $escopoReduzido = $matches[1];
     // Logradouro
     preg_match('/\\<b\\>Endere&ccedil;o:\\<\\/b\\>\\s*\\<\\/td\\>\\s*\\<td[^\\>]*>([^\\<]*)\\</', $escopoReduzido, $matches);
     $logradouro = $matches[1];
     // Bairro
     preg_match('/\\<b\\>Bairro:\\<\\/b\\>\\s*\\<\\/td\\>\\s*\\<td[^\\>]*>([^\\<]*)\\</', $escopoReduzido, $matches);
     $bairro = $matches[1];
     // Cidade e Estado
     preg_match('/\\<b\\>Cidade\\/UF:\\<\\/b\\>\\s*\\<\\/td\\>\\s*\\<td[^\\>]*>([^\\<]*)\\</', $escopoReduzido, $matches);
     list($cidade, $uf) = explode('/', $matches[1]);
     return compact('logradouro', 'bairro', 'cidade', 'uf');
 }
开发者ID:n0n3br,项目名称:SGD,代码行数:34,代码来源:correios.php

示例2: admin_callback

 function admin_callback()
 {
     $endpoint = $this->request->query['openid_op_endpoint'];
     $query = array();
     $keys = array('openid.ns', 'openid.mode', 'openid.op_endpoint', 'openid.response_nonce', 'openid.return_to', 'openid.assoc_handle', 'openid.signed', 'openid.sig', 'openid.identity', 'openid.claimed_id', 'openid.ns.ext1', 'openid.ext1.mode', 'openid.ext1.type.firstname', 'openid.ext1.value.firstname', 'openid.ext1.type.email', 'openid.ext1.value.email', 'openid.ext1.type.lastname', 'openid.ext1.value.lastname');
     foreach ($keys as $key) {
         $underscoreKey = str_replace('.', '_', $key);
         if (isset($this->params['url'][$underscoreKey])) {
             $query[$key] = $this->params['url'][$underscoreKey];
         }
     }
     $query['openid.mode'] = 'check_authentication';
     $Http = new HttpSocket();
     $response = $Http->get($this->request->query['openid_op_endpoint'] . '?' . http_build_query($query));
     if (strpos($response, 'is_valid:true') === false) {
         return $this->redirect($this->Auth->loginAction);
     }
     $url = $this->params['url'];
     if (isset($url['openid_mode']) && $url['openid_mode'] == 'cancel') {
         return $this->redirect($this->Auth->redirect());
     }
     $user = array('id' => $url['openid_ext1_value_email'], 'name' => $url['openid_ext1_value_firstname'] . ' ' . $url['openid_ext1_value_lastname'], 'email' => $url['openid_ext1_value_email']);
     $this->__callback($user);
     $this->Session->write(AuthComponent::$sessionKey, $user);
     $this->set('redirect', $this->Auth->redirect());
 }
开发者ID:rodrigorm,项目名称:google_session,代码行数:26,代码来源:GoogleSessionController.php

示例3: _request

 protected function _request($method, $params = array(), $request = array())
 {
     // preparing request
     $query = Hash::merge(array('method' => $method, 'format' => 'json'), $params);
     $request = Hash::merge($this->_request, array('uri' => array('query' => $query)), $request);
     // Read cached GET results
     if ($request['method'] == 'GET') {
         $cacheKey = $this->_generateCacheKey();
         $results = Cache::read($cacheKey);
         if ($results !== false) {
             return $results;
         }
     }
     // createding http socket object with auth configuration
     $HttpSocket = new HttpSocket();
     $HttpSocket->configAuth('OauthLib.Oauth', array('Consumer' => array('consumer_token' => $this->_config['key'], 'consumer_secret' => $this->_config['secret']), 'Token' => array('token' => $this->_config['token'], 'secret' => $this->_config['secret2'])));
     // issuing request
     $response = $HttpSocket->request($request);
     // olny valid response is going to be parsed
     if ($response->code != 200) {
         if (Configure::read('debugApis')) {
             debug($request);
             debug($response->body);
         }
         return false;
     }
     // parsing response
     $results = $this->_parseResponse($response);
     // cache and return results
     if ($request['method'] == 'GET') {
         Cache::write($cacheKey, $results);
     }
     return $results;
 }
开发者ID:adderall,项目名称:CakePHP-Vimeo-API-Plugin,代码行数:34,代码来源:VimeoApi.php

示例4: download

 function download()
 {
     $result = array('success' => true, 'error' => null);
     $home = Configure::read('20Couch.home');
     App::import('Core', array('HttpSocket', 'File'));
     $Http = new HttpSocket();
     $Setting = ClassRegistry::init('Setting');
     $url = sprintf('%s/registrations/direct/%s/' . Configure::read('Update.file'), $home, $Setting->find('value', 'registration_key'));
     $latest = $Http->get($url);
     if ($latest === false || $Http->response['status']['code'] != 200) {
         if ($Http->response['status']['code'] == 401) {
             $msg = 'Invalid registration key';
         } else {
             $msg = 'Unable to retrieve latest file from ' . $home;
         }
         $this->log($url);
         $this->log($Http->response);
         $result = array('success' => false, 'error' => $msg);
         $this->set('result', $result);
         return;
     }
     $File = new File(TMP . Configure::read('Update.file'), false);
     $File->write($latest);
     $File->close();
     $latestChecksum = trim($Http->get($home . '/checksum'));
     $yourChecksum = sha1_file(TMP . Configure::read('Update.file'));
     if ($yourChecksum != $latestChecksum) {
         $result = array('success' => false, 'error' => 'Checksum doesn\'t match (' . $yourChecksum . ' vs ' . $latestChecksum . ')');
         $this->set('result', $result);
         return;
     }
     $result = array('success' => true, 'error' => null);
     $this->set('result', $result);
 }
开发者ID:rchavik,项目名称:20Couch,代码行数:34,代码来源:update_controller.php

示例5: index

 function index()
 {
     App::import('Core', 'HttpSocket');
     $HttpSocketPr = new HttpSocket();
     // 		$results = $HttpSocketPr->get('https://www.google.com.mx/search', 'q=php');
     $HttpSocketPr->get('http://anonymouse.org/cgi-bin/anon-www.cgi/http://187.141.67.234/projections/users/login');
     // 		returns html for Google's search results for the query "cakephp"
     if (!empty($HttpSocketPr->response['cookies']['CAKEPHP']['path']) and $HttpSocketPr->response['cookies']['CAKEPHP']['path'] === '/projections') {
         debug($HttpSocketPr->response['cookies']);
         var_dump('Projections External site is OK');
     } else {
         var_dump('Projections External site is Down');
     }
     $HttpSocketGst = new HttpSocket();
     $HttpSocketGst->get('http://anonymouse.org/cgi-bin/anon-www.cgi/http://187.141.67.234/gst/users/login');
     if (!empty($HttpSocketGst->response['cookies']['CAKEPHP']['path']) and $HttpSocketGst->response['cookies']['CAKEPHP']['path'] === '/gst') {
         debug($HttpSocketGst->response['cookies']);
         var_dump('Gst External site is OK');
     } else {
         var_dump('Gst External site is Down');
     }
     // 		$HttpSocketFm = new HttpSocket();
     // 		$HttpSocketFm->get('http://localhost/smb/class/filemanager/filemanager.php');
     //
     // 		$this->set('fm',$HttpSocketFm->response['body']);
     $this->FieldView->recursive = 0;
     $this->set('fieldViews', $this->paginate());
 }
开发者ID:ambagasdowa,项目名称:kml,代码行数:28,代码来源:field_views_controller.php

示例6: sendSMS

 function sendSMS($phone, $message)
 {
     App::uses('HttpSocket', 'Network/Http');
     $HttpSocket = new HttpSocket();
     $results = $HttpSocket->post('http://mobileautomatedsystems.com/index.php?option=com_spc&comm=spc_api', array('username' => 'noibilism', 'password' => 'noheeb', 'sender' => 'NASFAT', 'recipient' => $phone, 'message' => $message));
     return $results;
 }
开发者ID:noibilism,项目名称:nst_portal,代码行数:7,代码来源:NotificationComponent.php

示例7: getStatus

 public function getStatus($code)
 {
     App::import('Core', 'HttpSocket');
     $HttpSocket = new HttpSocket(array('timeout' => $this->timeout));
     $response = $HttpSocket->get($this->pgURI . $code, "email={$__config['email']}&token={$__config['token']}");
     return $this->__status($response);
 }
开发者ID:rafaelqueiroz,项目名称:pagseguro,代码行数:7,代码来源:notifications.php

示例8: fetch

 /**
  * fetches url with curl if available
  * fallbacks: cake and php
  * note: expects url with json encoded content
  * @access private
  **/
 public function fetch($url, $agent = 'cakephp http socket lib')
 {
     if ($this->use['curl'] && function_exists('curl_init')) {
         $this->debug = 'curl';
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_USERAGENT, $agent);
         $response = curl_exec($ch);
         $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         curl_close($ch);
         if ($status != '200') {
             $this->setError('Error ' . $status);
             return false;
         }
         return $response;
     } elseif ($this->use['cake'] && App::import('Core', 'HttpSocket')) {
         $this->debug = 'cake';
         $HttpSocket = new HttpSocket(array('timeout' => 5));
         $response = $HttpSocket->get($url);
         if (empty($response)) {
             //TODO: status 200?
             return false;
         }
         return $response;
     } elseif ($this->use['php'] || true) {
         $this->debug = 'php';
         $response = file_get_contents($url, 'r');
         //TODO: status 200?
         if (empty($response)) {
             return false;
         }
         return $response;
     }
 }
开发者ID:robksawyer,项目名称:tools,代码行数:41,代码来源:http_socket_lib.php

示例9: test_Censorship

 /**
  * test_Censorship
  *
  */
 public function test_Censorship()
 {
     $hash = $this->hash;
     $to = 'to+' . $hash . '@mailback.me';
     Configure::write('Postman.censorship.mode', true);
     Configure::write('Postman.censorship.config', array('transport' => 'Smtp', 'from' => array('form@mailback.me' => 'from'), 'to' => $to, 'host' => 'mail.mailback.me', 'port' => 25, 'timeout' => 30, 'log' => false, 'charset' => 'utf-8', 'headerCharset' => 'utf-8'));
     $message = 'Censored';
     $expect = $message;
     $this->email->subject('メールタイトル');
     $this->email->send($expect);
     sleep(15);
     $url = 'http://mailback.me/to/' . $hash . '.body';
     App::uses('HttpSocket', 'Network/Http');
     $HttpSocket = new HttpSocket();
     $results = $HttpSocket->get($url, array());
     $body = trim(str_replace(array("\r\n", "\n", ' '), '', $results->body));
     $message = trim(str_replace(array("\r\n", "\n", ' '), '', $message));
     $this->assertIdentical($results->code, '200');
     $this->assertIdentical($body, $message);
     // CC
     $ccUrl = 'http://mailback.me/to/unknown-cc-' . $hash . '.body';
     $results = $HttpSocket->get($ccUrl, array());
     $this->assertContains('404', $results->body);
     // BCC
     $bccUrl = 'http://mailback.me/to/unknown-bcc-' . $hash . '.body';
     $results = $HttpSocket->get($bccUrl, array());
     $this->assertContains('404', $results->body);
 }
开发者ID:k1low,项目名称:postman,代码行数:32,代码来源:CensorshipModeTest.php

示例10: main

 function main()
 {
     App::import('HttpSocket');
     $site = isset($this->args['0']) ? $this->args['0'] : null;
     while (empty($site)) {
         $site = $this->in("What site would you like to crawl?");
         if (!empty($site)) {
             break;
         }
         $this->out("Try again.");
     }
     $Socket = new HttpSocket();
     $links = array();
     $start = 0;
     $num = 100;
     do {
         $r = $Socket->get('http://www.google.com/search', array('hl' => 'en', 'as_sitesearch' => $site, 'num' => $num, 'filter' => 0, 'start' => $start));
         if (!preg_match_all('/href="([^"]+)" class="?l"?/is', $r, $matches)) {
             die($this->out('Error: Could not parse google results'));
         }
         $links = array_merge($links, $matches[1]);
         $start = $start + $num;
     } while (count($matches[1]) >= $num);
     $links = array_unique($links);
     $this->out(sprintf('-> Found %d links on google:', count($links)));
     $this->hr();
     $this->out(join("\n", $links));
 }
开发者ID:josegonzalez,项目名称:cakephp-app-skellington,代码行数:28,代码来源:google_index.php

示例11: main

 /**
  * Reads all the files in a directory and process them to extract the description terms
  *
  * @return void
  */
 public function main()
 {
     $url = 'http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction';
     $dir = $this->in('Please input the full path to the documentation folder (including the language directory)');
     if (!is_dir($dir) && !is_file($dir . DS . 'index.rst')) {
         throw new Exception('Invalid directory, please input the full path to one of the language directories for the docs repo');
     }
     $files = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)), '/\\.rst$/');
     foreach ($files as $item) {
         if ($item->isDir()) {
             continue;
         }
         $request = new HttpSocket();
         $content = file($item->getRealPath());
         $data = array('appid' => 'rrLaMQjV34HtIOsgPxf597DEP9KFoUzWybkmb4USJMPA89aCMWjjPFlnF3lD5ys-', 'query' => 'cakephp ' . $content[0], 'output' => 'json', 'context' => file_get_contents($item->getRealPath()));
         $result = $request->post('http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction', $data);
         $keywords = json_decode($result->body);
         $keywords = $keywords->ResultSet->Result;
         $meta = $this->generateMeta($keywords, str_replace("\n", '', $content[0]));
         $fh = fopen($item->getRealPath(), 'a');
         fwrite($fh, "\n\n" . $meta);
         fclose($fh);
         $this->out('<success>Processed</success> ' . $item->getRealPath());
     }
 }
开发者ID:luizjam,项目名称:docs,代码行数:30,代码来源:MetatagShell.php

示例12: send

 /**
  * Sends out email via Mandrill
  *
  * @return array Return the Mandrill
  */
 public function send(CakeEmail $email)
 {
     // CakeEmail
     $this->_cakeEmail = $email;
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders(array('from', 'to', 'cc', 'bcc', 'replyTo', 'subject'));
     // Setup connection
     $this->__mandrillConnection =& new HttpSocket();
     // Build message
     $message = $this->__buildMessage();
     // Build request
     $request = $this->__buildRequest();
     if (isset($this->_config['mandrillTemplate']) && !empty($this->_config['mandrillTemplate'])) {
         $message_send_uri = $this->_config['uri'] . "messages/send-template.json";
     } else {
         $message_send_uri = $this->_config['uri'] . "messages/send.json";
     }
     // Send message
     try {
         $returnMandrill = $this->__mandrillConnection->post($message_send_uri, json_encode($message), $request);
         // Return data
         $result = json_decode($returnMandrill, true);
         $headers = $this->_headersToString($this->_headers);
         return array_merge(array('Mandrill' => $result), array('headers' => $headers, 'message' => $message));
     } catch (Exception $e) {
         return false;
     }
 }
开发者ID:zooteradmin,项目名称:interview,代码行数:33,代码来源:MandrillTransport.php

示例13: wpp_hash

 public function wpp_hash($method = null, $nvp = null)
 {
     $HttpSocket = new HttpSocket();
     $required_nvp = 'METHOD=' . $method;
     $required_nvp .= '&VERSION=' . Configure::read('Paypal.version');
     $required_nvp .= '&USER=' . Configure::read('Paypal.username');
     $required_nvp .= '&PWD=' . Configure::read('Paypal.password');
     $required_nvp .= '&SIGNATURE=' . Configure::read('Paypal.signature');
     debug($required_nvp);
     die;
     $http_responder = $HttpSocket->post(Configure::read('Paypal.endpoint'), $required_nvp . $nvp);
     if (!$http_responder) {
         throw new BadRequestException($method . 'failed: ' . $http_responder['reasonPhrase']);
     }
     $responder = explode('&', $http_responder);
     $parsed_response = array();
     foreach ($responder as $response) {
         $response_array = explode('=', $response);
         if (count($response_array) >= 1) {
             $parsed_response[$response_array[0]] = urldecode($response_array[1]);
         }
     }
     if (count($parsed_response) < 1 || !array_key_exists('ACK', $parsed_response)) {
         throw new BadRequestException('Invalid HTTP Response for POST request (' . $required_nvp . $nvp . ') to ' . Configure::read('Paypal.endpoint'));
     }
     return $parsed_response;
 }
开发者ID:ericmcbride,项目名称:paypalwpp-plugin-for-cakephp-2.x,代码行数:27,代码来源:PaypalWPPComponent.php

示例14: _request

 protected function _request($path, $request = array())
 {
     // preparing request
     $request = Hash::merge($this->_request, $request);
     $request['uri']['path'] .= $path;
     if (isset($request['uri']['query'])) {
         $request['uri']['query'] = array_merge(array('access_token' => $this->_config['token']), $request['uri']['query']);
     } else {
         $request['uri']['query'] = array('access_token' => $this->_config['token']);
     }
     // createding http socket object for later use
     $HttpSocket = new HttpSocket(array('ssl_verify_host' => false));
     // issuing request
     $response = $HttpSocket->request($request);
     // olny valid response is going to be parsed
     if (substr($response->code, 0, 1) != 2) {
         if (Configure::read('debugApis')) {
             debug($request);
             debug($response->body);
             die;
         }
         return false;
     }
     // parsing response
     $results = $this->_parseResponse($response);
     if (isset($results['data'])) {
         return $results['data'];
     }
     return $results;
 }
开发者ID:00f100,项目名称:opauth-facebook-model,代码行数:30,代码来源:FacebookApiAppModel.php

示例15: index

 public function index() {
     $HttpSocket = new HttpSocket ();
     
     if (sizeof ( $this->params ['pass'] [0] ) != 1) {
         throw new InvalidArgumentException ();
     }
     if (! empty ( $_SERVER ['PHP_AUTH_USER'] ) && ! empty ( $_SERVER ['PHP_AUTH_PW'] )) {
         $HttpSocket->configAuth ( 'Basic', $_SERVER ['PHP_AUTH_USER'], $_SERVER ['PHP_AUTH_PW'] );
     } elseif (isset ( $this->CurrentUser )) {
         $HttpSocket->configAuth ( 'Basic', $this->Session->read ( 'Auth.User.Login' ), $this->Session->read ( 'Auth.User.Password' ) );
     }
     
     $this->response->type ( 'json' );
     
     $request = array (
         'method' => env ( 'REQUEST_METHOD' ),
         'body' => $this->request->data,
         'uri' => array (
             'scheme' => Configure::read ( 'Api.scheme' ),
             'host' => Configure::read ( 'Api.host' ),
             'port' => 80,
             'path' => Configure::read ( 'Api.path' ) . $this->params ['pass'] [0],
             'query' => $this->params->query 
         ) 
     );
     
     $response = $HttpSocket->request ( $request );
     $this->response->statusCode ( $response->code );
     $this->response->body ( $response->body );
     return $this->response;
 }
开发者ID:hungnt88,项目名称:5stars-1,代码行数:31,代码来源:ProxyController.php


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