Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed using AFNetworking

后端 未结 3 1685
遇见更好的自我
遇见更好的自我 2020-12-15 05:34

I am using AFNetworking library to post data on server using POST method.

Following is my code

- (void) callLoginAPI:(NSDictionary *)dictProfile{
            


        
相关标签:
3条回答
  • 2020-12-15 06:06

    The problem comes from response parsing. You are trying to de-serialize a JSON reponse (which MUST be contained in either a NSArray or NSDictionary) however your response is none of the above (Most likely a simple string).

    Also, try to set the "allow fragments" to the response serializer.

    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
    
    0 讨论(0)
  • 2020-12-15 06:14

    May be you need authentication to access JSON response. Set authentication like that:

    [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"XYZ" password:@"xyzzzz"];
    

    Try this:

    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
    [self setResponseSerializer:responseSerializer];
    

    instead of:

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
    0 讨论(0)
  • 2020-12-15 06:27
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    //Request Serializer
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
    //Response Serializer
    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
    manager.responseSerializer = responseSerializer;
    
    0 讨论(0)
提交回复
热议问题