Advertisement
Speeedfire

Untitled

Feb 11th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.32 KB | None | 0 0
  1. <?php
  2. class Test {
  3.  
  4.     private $_data;
  5.     private $_url = 'http://localhost/api/index.php?r=api/test';
  6.  
  7.     public function __construct() {
  8.             $this->init();
  9.     }
  10.  
  11.         public function init() {
  12.             $this->_data = $this->getData();
  13.         }
  14.        
  15.     public function print_response() {
  16.             print_r($this->_geturl($this->_url, $this->_data, 'POST'));
  17.     }
  18.    
  19.     private function getData() {
  20.             return file_get_contents('data.txt');
  21.     }
  22.    
  23.     private function _geturl( $url, $data_string = null, $type = 'GET', $javascript_loop = 0, $timeout = 300 ){
  24.         $url = str_replace( "&amp;", "&", urldecode(trim($url)) );
  25.         //$cookie = tempnam ("/tmp", "CURLCOOKIE");
  26.         //$cookie = 'd:\tmp\CURLCOOKIE';       
  27.        
  28.         $ch = curl_init();
  29.         curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
  30.         curl_setopt( $ch, CURLOPT_URL, $url );
  31.             curl_setopt( $ch, CURLOPT_HEADER, false);
  32.         //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  33.         //curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  34.         curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
  35.         curl_setopt( $ch, CURLOPT_ENCODING, "UTF-8" );
  36.         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  37.         curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
  38.         curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls
  39.         curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
  40.         curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
  41.         curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
  42.         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);                                                                    
  43.         curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);      
  44.         curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
  45.         'Content-Type: application/json',                                                                                
  46.         'Content-Length: ' . strlen($data_string))                                                                      
  47.         );                                                    
  48.  
  49.         $content = curl_exec( $ch );
  50.         //$response = curl_getinfo( $ch );
  51.         curl_close ( $ch );
  52.  
  53.         return $content;
  54.     }
  55. }
  56.  
  57. $test = new Test();
  58. $test->print_response();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement