Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Test {
- private $_data;
- private $_url = 'http://localhost/api/index.php?r=api/test';
- public function __construct() {
- $this->init();
- }
- public function init() {
- $this->_data = $this->getData();
- }
- public function print_response() {
- print_r($this->_geturl($this->_url, $this->_data, 'POST'));
- }
- private function getData() {
- return file_get_contents('data.txt');
- }
- private function _geturl( $url, $data_string = null, $type = 'GET', $javascript_loop = 0, $timeout = 300 ){
- $url = str_replace( "&", "&", urldecode(trim($url)) );
- //$cookie = tempnam ("/tmp", "CURLCOOKIE");
- //$cookie = 'd:\tmp\CURLCOOKIE';
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt( $ch, CURLOPT_HEADER, false);
- //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
- //curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
- curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
- curl_setopt( $ch, CURLOPT_ENCODING, "UTF-8" );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
- curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
- curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
- curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data_string))
- );
- $content = curl_exec( $ch );
- //$response = curl_getinfo( $ch );
- curl_close ( $ch );
- return $content;
- }
- }
- $test = new Test();
- $test->print_response();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement