The iOS port code is as follows:
Afhttprequestoperationmanager *manage = [[Afhttprequestoperationmanager alloc]initwithbaseurl:[nsurl URLWithString: @ "Http://localhost:8000/login/signin"]];manage.requestserializer = [Afjsonrequestserializer serializer]; Manage.responseserializer = [Afjsonresponseserializer serializer]; [Manage.requestserializer setvalue:@ "Application/json" forhttpheaderfield:@ "Accept"]; Manage.responseSerializer.acceptableContentTypes = [Nsset setwithobjects:@ "Application/json", @ "Text/plain", @ "text /javascript ", @" Text/json ", @" text/html ", nil]; [Manage post:@ "Login/signin" Parameters:[self.mylogin Toparams] success:^ (afhttprequestoperation *operation, ID Responseobject) {Debuglog (@ "\n===========response===========\n%@:\n%@", @ "Login/signin", responseObject); [_activityindicator stopanimating]; _loginbutton.enabled = YES; } failure:^ (Afhttprequestoperation *operation, Nserror *error) {Debuglog (@ "\n===========response===========\n%@:\n %@ ", @" Login/signin ", error); [_Activityindicator stopanimating]; _loginbutton.enabled = YES; }];
The code for Laravel is as follows:
routes.php----------Route::post('login/signin',[ 'as'=>'signin','uses'=>'Login\LoginController@signin']);LoginController.php----------public function signin(){ $message = "登录成功"; $data = array('phone'=>'13800138000','password'=>'123456'); $code = 0; return response()->json(['message'=>$message,'data'=>$data,'code'=>0]);}
Prompt error:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7fe00d90a3a0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
But change the Route::p OST to Route::get
Manage post:@ "Login/signin" changed to manage get:@ "Login/signin"
You can return data as follows:
{ code = 0; data = { password = 123456; phone = 13800138000; }; message = "\U767b\U5f55\U6210\U529f";}
Ask the question where, ask for help, thank you: D.
Using paw to view post data there will be PHP errors as follows:
Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid thiswarning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0Warning: Cannot modify header information - headers already sent in Unknown on line 0
Reply content:
The iOS port code is as follows:
Afhttprequestoperationmanager *manage = [[Afhttprequestoperationmanager alloc]initwithbaseurl:[nsurl URLWithString: @ "Http://localhost:8000/login/signin"]];manage.requestserializer = [Afjsonrequestserializer serializer]; Manage.responseserializer = [Afjsonresponseserializer serializer]; [Manage.requestserializer setvalue:@ "Application/json" forhttpheaderfield:@ "Accept"]; Manage.responseSerializer.acceptableContentTypes = [Nsset setwithobjects:@ "Application/json", @ "Text/plain", @ "text /javascript ", @" Text/json ", @" text/html ", nil]; [Manage post:@ "Login/signin" Parameters:[self.mylogin Toparams] success:^ (afhttprequestoperation *operation, ID Responseobject) {Debuglog (@ "\n===========response===========\n%@:\n%@", @ "Login/signin", responseObject); [_activityindicator stopanimating]; _loginbutton.enabled = YES; } failure:^ (Afhttprequestoperation *operation, Nserror *error) {Debuglog (@ "\n===========response===========\n%@:\n %@ ", @" Login/signin ", error); [_Activityindicator stopanimating]; _loginbutton.enabled = YES; }];
The code for Laravel is as follows:
routes.php----------Route::post('login/signin',[ 'as'=>'signin','uses'=>'Login\LoginController@signin']);LoginController.php----------public function signin(){ $message = "登录成功"; $data = array('phone'=>'13800138000','password'=>'123456'); $code = 0; return response()->json(['message'=>$message,'data'=>$data,'code'=>0]);}
Prompt error:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7fe00d90a3a0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
But change the Route::p OST to Route::get
Manage post:@ "Login/signin" changed to manage get:@ "Login/signin"
You can return data as follows:
{ code = 0; data = { password = 123456; phone = 13800138000; }; message = "\U767b\U5f55\U6210\U529f";}
Ask the question where, ask for help, thank you: D.
Using paw to view post data there will be PHP errors as follows:
Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid thiswarning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0Warning: Cannot modify header information - headers already sent in Unknown on line 0
Phpinfo () Know always_populate_raw_post_data modification becomes-1