2013-04-09 4 views
1

내가 서버에이 호출을하고나는 그것의 태그

휴식 CodeIgniter는 JSON에 문제가 있어요 문제를 폐쇄하지 휴식 CodeIgniter는 JSON과 문제가 발생하고 그 자신은 JSON 태그

을 폐쇄하지 않는 것이 "id": "19", "uid": null ","idipad ":"2 ","dateModified ": null}, {"id ":"19 ","uid ":

null, "name": "Wayne Corporation, Inc.", "phone": "932345324", "address": "두 번째. 312, Gotham City ","clientUID ":"7 ","email ":"[email protected] ","idipad ":"1 ","dateModified ": null}]

마지막 누락}

$this->response(array('login'=>'login success!','user_admin_id'=>$user_id,'client'=>$client,'users'=>$users,'projects'=>$projects,'plans'=>$plans,'meetings'=>$meetings,'demands'=>$demands,'tasks'=>$tasks,'presences'=>$presences,'contractors'=>$contractors,'companies'=>$companies), 200); 

이 클라이언트 호출을 사용하여 컬입니다 :

는 응답 생성하는 코드입니다

을 $ this-> curl-> 생성 ('http://dev.onplans.ch/onplans/index.php/api/example/login/format/json'는)

// Option & Options 
$this->curl->option(CURLOPT_BUFFERSIZE, 10); 
$this->curl->options(array(CURLOPT_BUFFERSIZE => 10)); 

// More human looking options 
$this->curl->option('buffersize', 10); 

// Login to HTTP user authentication 
$this->curl->http_login('admin', '1234'); 

// Post - If you do not use post, it will just run a GET request 
//$post = array('remember'=>'true','email'=>'[email protected]','password'=>'password'); 
     $post = array('remember'=>'true','email'=>'[email protected]','password'=>'password'); 
$this->curl->post($post); 

// Cookies - If you do not use post, it will just run a GET request 
$vars = array('remember'=>'true','email'=>'[email protected]','password'=>'password'); 
$this->curl->set_cookies($vars); 

// Proxy - Request the page through a proxy server 
// Port is optional, defaults to 80 
//$this->curl->proxy('http://example.com', 1080); 
//$this->curl->proxy('http://example.com'); 

// Proxy login 
//$this->curl->proxy_login('username', 'password'); 

// Execute - returns responce 
echo $this->curl->execute(); 

// Debug data ------------------------------------------------ 

// Errors 
$this->curl->error_code; // int 
$this->curl->error_string; 


     print_r('error :::::LOGINN REMOTE:::::'.$this->curl->error_string); 
// Information 
$this->curl->info; // array 

     print_r('info :::::::::::::'.$this->curl->info); 

응답이 필

이 답변이 Github issue에서 참조 된
/** 
* Response 
* 
* Takes pure data and optionally a status code, then creates the response. 
* 
* @param array $data 
* @param null|int $http_code 
*/ 
public function response($data = array(), $http_code = null) 
{ 
    global $CFG; 

    // If data is empty and not code provide, error and bail 
    if (empty($data) && $http_code === null) 
    { 
     $http_code = 404; 

     // create the output variable here in the case of $this->response(array()); 
     $output = NULL; 
    } 

    // If data is empty but http code provided, keep the output empty 
    else if (empty($data) && is_numeric($http_code)) 
    { 
     $output = NULL; 
    } 

    // Otherwise (if no data but 200 provided) or some data, carry on camping! 
    else 
    { 
     // Is compression requested? 
     if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE) 
     { 
      if (extension_loaded('zlib')) 
      { 
       if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) 
       { 
        ob_start('ob_gzhandler'); 
       } 
      } 
     } 

     is_numeric($http_code) OR $http_code = 200; 

     // If the format method exists, call and return the output in that format 
     if (method_exists($this, '_format_'.$this->response->format)) 
     { 
      // Set the correct format header 
      header('Content-Type: '.$this->_supported_formats[$this->response->format]); 

      $output = $this->{'_format_'.$this->response->format}($data); 
     } 

     // If the format method exists, call and return the output in that format 
     elseif (method_exists($this->format, 'to_'.$this->response->format)) 
     { 
      // Set the correct format header 
      header('Content-Type: '.$this->_supported_formats[$this->response->format]); 

      $output = $this->format->factory($data)->{'to_'.$this->response->format}(); 
     } 

     // Format not supported, output directly 
     else 
     { 
      $output = $data; 
     } 
    } 

    header('HTTP/1.1: ' . $http_code); 
    header('Status: ' . $http_code); 

    // If zlib.output_compression is enabled it will compress the output, 
    // but it will not modify the content-length header to compensate for 
    // the reduction, causing the browser to hang waiting for more data. 
    // We'll just skip content-length in those cases. 
    if (! $this->_zlib_oc && ! $CFG->item('compress_output')) 
    { 
     header('Content-Length: ' . strlen($output)); 
    } 

    exit($output); 
} 
+0

'response' 메소드에는 무엇이 있습니까? –

+0

응답은 phil sturgeon의 나머지 api에 속합니다. –

답변

2

에서 나머지 API를 CodeIgniter의에 속한다. 또한 Pedro Dinis에 의해 제기, 나는 손님. 오늘이 문제를 만났습니다. 솔루션을 검색하는 데 오랜 시간이 걸립니다. 나는 나와 같은 누군가를 도울 희망으로 여기를 나눕니다. 의 핵심은 라이브러리 파일에 라인 (430)의 주위에 대체하는 것입니다 : REST_Controller.php :

header('Content-Length: ' . strlen($output)); 

UPDATE

header('Content-Length: ' . strlen("'".$output."'")); 

의 : 문제는 solved here 이었다 또는 당신은 단지 그것을 코드를 주석 수 있습니다 잘 돌아갈거야. :)

관련 문제