laravel Web服务响应返回null值

时间:2014-05-23 07:33:30

标签: laravel laravel-4

plz找到以下代码

客户端

public function index()
{

    $username = Session::get('username');
    $password = Session::get('password');

    $url = url('/languagesService');

    $data = json_encode(array("username" => $username,"password" => $password));
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_HEADER,false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    $response = CURL_EXEC($ch);
    $data = json_decode($response,true);
            return $data;//return $response tried both. 

}

服务器

public function index()
{
$user = array(
        'username' => Input::get('username'),
        'password' => Input::get('password')
    );



    if ( Auth::attempt($user) ) {
        $data = languages::all();         
    }else {
        $data = array("invalid" => "Invalid username and password");
    }

    $response = Response::json($data,200);
    return $response;
       //return View::make("languages.index")->with("languages",$languages);
}

直接访问服务器时,它以json格式输出响应。但通过客户端访问,它什么都不响应。获得空白输出。尝试使用硬编码响应,仍然是相同的空白输出。我错过了很重要的东西吗?

0 个答案:

没有答案