iOS calls Laravel interface returns error message

Source: Internet
Author: User
Tags deprecated
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.