Exemplo n.º 1
0
        public function Login()
        {
            $signature = $this->SignMessage("frob", $this->Frob, "perms", "delete");
            $query = "api_key={$this->ApiKey}&perms=delete&frob={$this->Frob}&api_sig={$signature}";
            
            $request = new HttpRequest("http://flickr.com/services/auth/", HTTP_METH_GET);
            $request->setQueryData($query);
            $request->enableCookies();
            
            
            $request->setOptions(array(    "redirect" => 10, 
		                                   "useragent" => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
		                              )
		                        );
            
            $request->send();
            
            var_dump($request->getResponseCode());
            print_r($request->getResponseBody());
            var_dump($request->getResponseStatus());
        }
Exemplo n.º 2
0
 protected function doDelete($action, array $data)
 {
     $module = empty($action) ? substr($this->module, 0, -1) : $this->module;
     if (strrpos($action, '.json') === false) {
         $action .= '.json';
     }
     array_walk_recursive($data, 'Lupin_Model_API::encode');
     $url = $this->hostname . $module . $action;
     $request = new HttpRequest($url, HTTP_METH_DELETE);
     $request->setQueryData($data);
     try {
         $request->send();
     } catch (Exception $e) {
         return false;
     }
     $this->responseCode = $request->getResponseCode();
     if ($request->getResponseCode() !== 200) {
         return false;
     }
     return $request->getResponseHeader();
 }
Exemplo n.º 3
0
 /**
  * Test an action
  *
  * This is the test action method. It test a specific action.
  *
  * @return void
  */
 public function testAction()
 {
     $this->_helper->viewRenderer->setViewSuffix('txt');
     // The options we are accepting for adding
     $options = new Zend_Console_Getopt(array('name|n=s' => 'Name of the action to call.', 'parameters|p=s' => 'Paramters to use. For example var1=val1&var2=val2', 'format|f=s' => 'Format to return. Defaults to XML.', 'method|m=s' => 'Method to use. Defaults to GET.', 'email|e=s' => 'Email or username to use.', 'secretkey|sk=s' => 'Secret key associated with email passed.', 'domain|d=s' => 'Domain to use, if not included will use default', 'query-uri|u=s' => 'Query uri to use. For example /testing/1', 'https|h' => 'Use https.'));
     try {
         $options->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         $this->view->message = $e->getUsageMessage();
         return;
     }
     if ($options->name == '') {
         $this->view->message = $options->getUsageMessage();
         return;
     }
     $confModel = new Default_Model_Configuration();
     if (!$confModel->getKey('api_url')) {
         $this->view->message = 'Remember you can set the default API domain name in your admin configuration.' . PHP_EOL;
     }
     if (!class_exists('HttpRequest')) {
         $this->view->message = 'HttpRequest class was not found the pecl_http (http://pecl.php.net/package/pecl_http) package is required to use the tester.' . PHP_EOL;
         return;
     }
     $action_name = $options->name;
     $params = $options->parameters;
     $format = $options->format;
     $method = $options->method;
     $email = $options->email;
     $password = $options->secretkey;
     $url = $options->domain;
     $ssl = $options->https;
     $query_uri = $options->getOption('query-uri');
     if ($url == '') {
         $url = $confModel->getKey('api_url');
     }
     if ($query_uri == '') {
         $actionModel = new Default_Model_Action();
         $actions = $actionModel->getAll();
         foreach ($actions as $action_details) {
             if ($action_details['name'] == $action_name) {
                 $query_uri = $action_details['route'];
             }
         }
     }
     $newMethod = HTTP_METH_GET;
     switch (strtolower($method)) {
         case 'get':
             $newMethod = HTTP_METH_GET;
             break;
         case 'post':
             $newMethod = HTTP_METH_POST;
             break;
         case 'put':
             $newMethod = HTTP_METH_PUT;
             break;
         case 'delete':
             $newMethod = HTTP_METH_DELETE;
             break;
         case 'head':
             $newMethod = HTTP_METH_HEAD;
             break;
     }
     $request_url = 'http' . ($ssl !== null ? 's' : '') . '://' . $url . '/' . $query_uri . '.' . strtolower($format);
     $httpOptions = array();
     if ($email && $password) {
         $httpOptions = array('headers' => array('Accept' => '*/*'), 'httpauth' => $email . ':' . $password, 'httpauthtype' => HTTP_AUTH_DIGEST);
     }
     $request = new HttpRequest($request_url, $newMethod, $httpOptions);
     if ("POST" == strtoupper($method)) {
         $request->setBody($params);
     } else {
         $request->setQueryData($params);
     }
     $res = $request->send();
     $responseInfo = $request->getResponseInfo();
     $this->view->request_url = $responseInfo['effective_url'];
     $this->view->response_header = $this->collapseHeaders($res->getHeaders());
     $this->view->content = $res->getBody();
     $this->view->status = $res->getResponseCode();
     $this->view->method = isset($method) ? strtoupper($method) : 'GET';
     $this->view->request_post_fields = $newMethod == HTTP_METH_POST ? $params : '';
 }
Exemplo n.º 4
0
<?php

$r = new HttpRequest('http://www.google.com/search');
// store Googles cookies in a dedicated file
touch('google.txt');
$r->setOptions(array('cookiestore' => 'google.txt'));
$r->setQueryData(array('q' => '+"pecl_http" -msg -cvs -list', 'hl' => 'de'));
// HttpRequest::send() returns an HttpMessage object
// of type HttpMessage::RESPONSE or throws an exception
try {
    print $r->send()->getBody();
} catch (HttpException $e) {
    print $e;
}
Exemplo n.º 5
0
 $job->Recipients[$i]->attempts++;
 if ($job->Recipients[$i]->attempts > SMS_MAX_ATTEMPTS_PER_RECIPIENT) {
     waitIfNeeded($start);
     continue;
 }
 // Rotate, round-robin style, through the available sender numbers
 $senderNumber = $numbers[$iterations % count($numbers)];
 // Apply template values to the message, if any
 $nameArray = explode(" ", trim($recipName));
 if (!$nameArray || count($nameArray) == 0 || !trim($nameArray[0])) {
     $nameArray = array($recipName);
 }
 $message = str_replace("{FIRSTNAME}", trim($nameArray[0]), $job->Message);
 // Set up the query's parameters
 $query = array("api_key" => SMS_API_KEY, "api_secret" => SMS_API_SECRET, "from" => $senderNumber, "to" => $recipPhone, "text" => $message);
 $request->setQueryData($query);
 // Send the text message
 $request->send();
 $response = json_decode($request->getResponseBody());
 if (!$job->SegmentCount) {
     $job->SegmentCount = $response->{'message-count'};
 }
 // Each segment in the response contains its own cost and potentially an error code
 foreach ($response->messages as $segment) {
     if ($segment->status == 0) {
         // Successful send.
         // Convert cost from EUR to USD (https://getsatisfaction.com/nexmo/topics/is_the_message_price_thats_returned_from_a_rest_request_in_eur_or_usd)
         $job->Cost += $segment->{'message-price'} * $euroToUsd;
     } else {
         // Problem sending.
         // Status codes available at: https://docs.nexmo.com/index.php/messaging-sms-api/send-message
Exemplo n.º 6
0
<?php

$request = new HttpRequest();
$request->setUrl('http://mockbin.com/har');
$request->setMethod(HTTP_METH_GET);
$request->setQueryData(array('foo' => array('bar', 'baz'), 'baz' => 'abc', 'key' => 'value'));
try {
    $response = $request->send();
    echo $response->getBody();
} catch (HttpException $ex) {
    echo $ex;
}