IOS returns an error message when calling the Laravel Interface

Source: Internet
Author: User
The iOS code is as follows: {code ...} the Laravel code is as follows: {code ...} error message: ErrorDomainNSCocoaErrorDomainCode3840 & quot; Theoperationcouldn 'tbecompleted. (Cocoaerror3840.) & quot; (JSONtextdidnotstartwithar... the iOS 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 Laravel code is as follows:

Routes. php ---------- Route: post ('login/signin', ['as' => 'signature', 'uses '=> 'login \ LoginController @ signin']); LoginController. php ---------- public function signin () {$ message = "Logon successful"; $ data = array ('phone' => '000000', 'Password' => '000000 '); $ code = 0; return response ()-> json (['message' => $ message, 'data' => $ data, 'code' => 0]);}

Error message: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.}

However, change Route: post to Route: getmanage POST: @ "login/signin" to manage GET: @ "login/signin"

You can return the following data:

{    code = 0;    data =     {        password = 123456;        phone = 13800138000;    };    message = "\U767b\U5f55\U6210\U529f";}

Where is the problem? Could you help me? Thank you: D.

When you use Paw to view POST data, the following php error occurs:

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 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 Laravel code is as follows:

Routes. php ---------- Route: post ('login/signin', ['as' => 'signature', 'uses '=> 'login \ LoginController @ signin']); LoginController. php ---------- public function signin () {$ message = "Logon successful"; $ data = array ('phone' => '000000', 'Password' => '000000 '); $ code = 0; return response ()-> json (['message' => $ message, 'data' => $ data, 'code' => 0]);}

Error message: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.}

However, change Route: post to Route: getmanage POST: @ "login/signin" to manage GET: @ "login/signin"

You can return the following data:

{    code = 0;    data =     {        password = 123456;        phone = 13800138000;    };    message = "\U767b\U5f55\U6210\U529f";}

Where is the problem? Could you help me? Thank you: D.

When you use Paw to view POST data, the following php error occurs:

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 () knows always_populate_raw_post_data and changes it to-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.