1
votes

I'm trying send post request to server with AFNetworking 2.0

NSDictionary * dict = @{@"credentials": @{
                                @"name": @"Valod",
                                @"password": @"test"
                                }
                        };

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

[manager POST:URL parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];`

but I'm getting the error

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7fd6214a5d70 {NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x7fd62150ec60 "Request failed: internal server error (500)"}

I test api call with google application.And the response json is valid json

1
possible duplicate of Cocoa error 3840 using JSON (iOS)Eimantas
I see this post but it doesn't help meSergey Davtyan

1 Answers

0
votes

Check your requestSerializer, maybe it 's AFHTTPRequestSerializer instead of AFJSONRequestSerializer. Try setting manager.requestSerializer = [AFJSONRequestSerializer serializer];