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.