本文整理汇总了PHP中HttpSocket::post方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpSocket::post方法的具体用法?PHP HttpSocket::post怎么用?PHP HttpSocket::post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpSocket
的用法示例。
在下文中一共展示了HttpSocket::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
示例2: api
/**
* Method of API
*
* @return HttpSocketResponse
*/
public function api()
{
$args = func_get_args();
$url = implode('/', array(self::URL, 'api', array_shift($args))) . ".json";
do {
$data = array_merge($this->settings, array_shift($args));
} while ($args);
return $this->http->post($url, $data);
}
示例3: 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;
}
示例4: sendSMS
function sendSMS($phone, $message)
{
App::uses('HttpSocket', 'Network/Http');
$HttpSocket = new HttpSocket();
$results = $HttpSocket->post('http://www.mobileautomatedsystems.com/components/com_spc/smsapi.php', array('username' => 'noibilism', 'password' => 'noheeb', 'sender' => 'ZEO Ifo', 'recipient' => $phone, 'message' => $message));
return $results;
}
示例5: _doCall
/**
* Wrapper for calling the remote API
*
* @throws RuntimeException When an error is returned by Google
* @return HttpSocket instance
*/
protected function _doCall($uri, $query)
{
$result = false;
if (!is_a($this->Http, 'HttpSocket')) {
App::import('Core', 'HttpSocket');
$this->Http = new HttpSocket();
}
$query['v'] = $this->__version;
if ($this->useUserIp) {
App::import('Component', 'RequestHandler');
$RequestHandler = new RequestHandlerComponent();
$query['userip'] = $RequestHandler->getClientIP();
}
if (!is_null($this->key)) {
$query['key'] = $this->key;
}
$response = $this->Http->post($uri, $query);
if ($this->Http->response['status']['code'] == 200) {
$response = json_decode($response, true);
if ($response['responseStatus'] != 200) {
throw new RuntimeException($response['responseDetails']);
}
$result = $response['responseData'];
}
return $result;
}
示例6: 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ç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');
}
示例7: 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());
}
}
示例8: testPostViaSocket
public function testPostViaSocket()
{
$url = 'https://www.sofort.com/payment/notAvailable';
$SofortLibHttpSocket = new HttpSocket($url);
$SofortLibHttpSocket->post('test');
$httpCode = $SofortLibHttpSocket->getHttpCode();
$this->assertTrue($httpCode['code'] === 404);
$this->assertTrue($httpCode['message'] === '<errors><error><code>0404</code><message>URL not found ' . $url . '</message></error></errors>');
}
示例9: makeRequest
/**
* Makes an HTTP request using HttpSocket.
*
* @param string $url The URL to make the request to
* @param array $params The parameters to use for the POST body
* @param CurlHandler $ch Initialized curl handle. (Hopefully this is never used...)
*
* @return string The response text
*/
protected function makeRequest($url, $params, $ch = null)
{
App::import('Core', 'HttpSocket');
$HttpSocket = new HttpSocket();
$result = $HttpSocket->post($url, $params);
if ($result === false || $HttpSocket->response['status']['code'] != '200') {
$execption = new FacebookApiException(array('error_code' => $HttpSocket->response['status']['code'], 'error' => array('message' => $HttpSocket->response['status']['reason-phrase'], 'type' => 'HttpSocketException')));
throw $execption;
}
return $result;
}
示例10: request_add
public function request_add()
{
$link = Router::url('/', true) . 'rest_posts.json';
$data = null;
$httpSocket = new HttpSocket();
$data['Post']['title'] = 'New Post Title';
$data['Post']['body'] = 'New Post Body';
$response = $httpSocket->post($link, $data);
$this->set('response_code', $response->code);
$this->set('response_body', $response->body);
$this->render('/Client/request_response');
}
示例11: _postageappSend
/**
* Posts the data to the postmark API endpoint
*
* @return array
* @throws CakeException
*/
protected function _postageappSend()
{
$this->_generateSocket();
$request = array('header' => array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
$data = array('api_key' => $this->_config['apiKey'], 'uid' => String::uuid(), 'arguments' => $this->_data);
$return = $this->_socket->post($this->_apiUri, json_encode($data), $request);
$response = json_decode($return);
if ($this->_socket->response->code != '200') {
throw new CakeException($response->response->message);
}
$this->_content = array('headers' => array(), 'message' => $this->_data, 'response' => $response);
}
示例12: githubIssue
/**
* Creates a github issue with title and body in configured project.
*
* @param string $title
* @param string $body
* @throws BadRequestException
*/
public function githubIssue($type, $title, $body)
{
$socket = new HttpSocket();
$url = static::GITHUB_URL . '/repos/' . Configure::read('Feedback.github.project') . '/issues';
$data = json_encode(array('title' => $title, 'body' => $body, 'labels' => array_merge(array($type), Configure::read('Feedback.github.labels'))));
$result = $socket->post($url, $data, array('header' => array('Authorization' => 'token ' . Configure::read('Feedback.github.auth_token'))));
if (!in_array((int) $result->code, array(200, 201, 202, 203, 204, 205, 206))) {
throw new BadRequestException('Error entering feedback.');
}
$body = json_decode($result->body, true);
return $body['html_url'];
}
示例13: request_login
public function request_login()
{
// remotely post the information to the server
$link = "http://" . $_SERVER['HTTP_HOST'] . $this->webroot . 'users.json';
$data = null;
$httpSocket = new HttpSocket();
$data['User']['username'] = 'holaa';
$data['User']['password'] = 'blablabla';
$response = $httpSocket->post($link, $data);
$this->set('response_code', $response->code);
$this->set('response_body', $response->body);
$this->render('/Client/request_response');
}
示例14: send
/**
* Sends out email via Mandrill
*
* @param $email
* @return array Return the Mandrill
*/
public function send(CakeEmail $email)
{
//todo:check restricted_emails
$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();
$message = $this->__buildMessage();
$request = array('header' => array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
if ($this->_cakeEmail->template()['template']) {
$message_send_uri = $this->_config['uri'] . "messages/send-template.json";
} else {
$message_send_uri = $this->_config['uri'] . "messages/send.json";
}
//perform the http connection
$returnMandrill = $this->__mandrillConnection->post($message_send_uri, json_encode($message), $request);
//parse mandrill results
$result = json_decode($returnMandrill, true);
$headers = $this->_headersToString($this->_headers);
return array_merge(array('Mandrill' => $result), array('headers' => $headers, 'message' => $message));
}
示例15: add
public function add()
{
// remotely post the information to the server
$link = "http://" . $_SERVER['HTTP_HOST'] . $this->webroot . 'posts.json';
$data = null;
$data['Post']['title'] = "this is new title";
$data['Post']['content'] = "this is new content";
$httpSocket = new HttpSocket();
$response = $httpSocket->post($link, $data);
$this->set('response_code', $response->code);
$this->set('response_body', $response->body);
$this->set('link', $link);
$this->render('/client/request_response');
}