Php Laravel 4.2尝试使用post方法授权用户
我正在尝试发出post请求以授权用户 这是我的route.phpPhp Laravel 4.2尝试使用post方法授权用户,php,ios,json,laravel-4,Php,Ios,Json,Laravel 4,我正在尝试发出post请求以授权用户 这是我的route.php Route::post('/user/login', 'OwnerController@login'); 以下是我的登录方法: $login_by = Input::get('login_by'); $device_token = Input::get('device_token'); $device_type = Input::get('device_type'); if (Input::has('e
Route::post('/user/login', 'OwnerController@login');
以下是我的登录方法:
$login_by = Input::get('login_by');
$device_token = Input::get('device_token');
$device_type = Input::get('device_type');
if (Input::has('email') && Input::has('password')) {
$email = Input::get('email');
$password = Input::get('password');
$validator = Validator::make(
array(
'password' => $password,
'email' => $email,
'device_token' => $device_token,
'device_type' => $device_type,
'login_by' => $login_by
), array(
'password' => 'required',
'email' => 'required|email',
'device_token' => 'required',
'device_type' => 'required|in:android,ios',
'login_by' => 'required|in:manual,facebook,google'
)
);
if ($validator->fails()) {
$error_messages = $validator->messages()->all();
$response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
$response_code = 200;
Log::error('Validation error during manual login for owner = ' . print_r($error_messages, true));
} else {
if ($owner = Owner::where('email', '=', $email)->first()) {
if (Hash::check($password, $owner->password)) {
if ($login_by !== "manual") {
$response_array = array('success' => false, 'error' => 'Login by mismatch', 'error_code' => 417);
$response_code = 200;
} else {
if ($owner->device_type != $device_type) {
$owner->device_type = $device_type;
}
if ($owner->device_token != $device_token) {
$owner->device_token = $device_token;
}
$owner->token = generate_token();
$owner->token_expiry = generate_expiry();
$owner->save();
/* SEND REFERRAL & PROMO INFO */
$settings = Settings::where('key', 'referral_code_activation')->first();
$referral_code_activation = $settings->value;
if ($referral_code_activation) {
$referral_code_activation_txt = "referral on";
} else {
$referral_code_activation_txt = "referral off";
}
$settings = Settings::where('key', 'promotional_code_activation')->first();
$promotional_code_activation = $settings->value;
if ($promotional_code_activation) {
$promotional_code_activation_txt = "promo on";
} else {
$promotional_code_activation_txt = "promo off";
}
/* SEND REFERRAL & PROMO INFO */
$code_data = Ledger::where('owner_id', '=', $owner->id)->first();
$response_array = array(
'success' => true,
'id' => $owner->id,
'first_name' => $owner->first_name,
'last_name' => $owner->last_name,
'phone' => $owner->phone,
'email' => $owner->email,
'picture' => $owner->picture,
'bio' => $owner->bio,
'address' => $owner->address,
'state' => $owner->state,
'country' => $owner->country,
'zipcode' => $owner->zipcode,
'login_by' => $owner->login_by,
'social_unique_id' => $owner->social_unique_id,
'device_token' => $owner->device_token,
'device_type' => $owner->device_type,
'timezone' => $owner->timezone,
'token' => $owner->token,
'referral_code' => $code_data->referral_code,
'is_referee' => $owner->is_referee,
'promo_count' => $owner->promo_count,
'is_referral_active' => $referral_code_activation,
'is_referral_active_txt' => $referral_code_activation_txt,
'is_promo_active' => $promotional_code_activation,
'is_promo_active_txt' => $promotional_code_activation_txt,
);
$dog = Dog::find($owner->dog_id);
if ($dog !== NULL) {
$response_array = array_merge($response_array, array(
'dog_id' => $dog->id,
'age' => $dog->age,
'name' => $dog->name,
'breed' => $dog->breed,
'likes' => $dog->likes,
'image_url' => $dog->image_url,
));
}
$response_code = 200;
}
} else {
$response_array = array('success' => false, 'error' => 'Invalid Username and Password', 'error_code' => 403);
$response_code = 200;
}
} else {
$response_array = array('success' => false, 'error' => 'Not a Registered User', 'error_code' => 404);
$response_code = 200;
}
}
return Response::make(json_encode($response_array,JSON_PRETTY_PRINT))->header('Content-Type', "application/json");
但当我尝试使用AFNETWORKING从ios项目访问此url时:
我得到了这个错误:
URL:}{状态代码:
500,标题{
“缓存控制”=“无缓存”;
连接=关闭;
“内容长度”=4390;
“内容类型”=“文本/html;字符集=UTF-8”;
日期=“2016年2月8日星期一09:04:56 GMT”;
Server=“Apache/2.4.17(Win32)OpenSSL/1.0.2d PHP/5.6.14”;
“设置Cookie”=“laravel_session=EYJPDII6IIS2VNVUN2JW9UMEFKCTBKKUKJTNWC9PSISINZHBHVLIKOIVPMEW1KBKRMBLA2K1HSNGPBSHPHHAHNGT2A3HAB1BANMPVQ3NDVLFBOZNFUM3QRDJR3DWLQUFWTFZI3VKT0ZUCLDIYUXQNME1 QNLT3HJJJJJB3PT0ILCJTYWMIOI0QJJJJJJJJJKMJKMJKMW2JJJKMZMY2Y2Y2Y2Y2MZMZMZMZY3MZMZMZY3D4MZMZZZZMZMZY33D”;
expires=Mon,08-Feb-2016 11:04:57 GMT;最大年龄=7200;路径=/;
httponly”;
“X-Powered-By”=“PHP/5.6.14”},NSLocalizedDescription=请求失败:不可接受的内容类型:text/html}}}}}2016-02-08
14:34:43.948上[23084:6636866]登录响应-->(空)
是否有任何特定的方法可以生成类似webservice的方法并打印json?IOS调用或Web输出中是否存在问题
感谢服务器抛出状态代码500的错误统计信息,因此服务器端一定出了问题。你能看看在laravel.log中输出了什么吗?