dipesh sisodiya
dipesh sisodiya

Reputation: 35

Getting issue while fetching data from API via Afnetworking

I am using iOS, Objective-C, AFNetworing manager, POST, JSON data. This is my code but that not giving me data.

My Code:

NSString *strUrl2 = @"http://example.extension/admin/services/login.php";

NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];
[dataDict setValue:@"[email protected]" forKey:@"email"];
[dataDict setValue:@"123456" forKey:@"password"];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [[AFJSONRequestSerializer alloc] init];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json",@"application/x-www-form-urlencoded",@"png/jpg" , nil];

[manager POST:strUrl2
   parameters:dataDict
      success:^(AFHTTPRequestOperation* operation, id responseObject){
          
          NSLog(@"Response: %@", responseObject);
                   }
      failure:^(AFHTTPRequestOperation* operation, NSError* error){
          NSLog(@"Error: %@", error);
          // Releasing the semaphore to end the process from waiting state.
          
      }];

Not getting actual response.

Getting response:

{
  login = {
     message = "Please fill all required parameters";
     status = failure;
  };
}

Note:

This web service work on postMan and Android.

Upvotes: 0

Views: 305

Answers (1)

Harshal Valanda
Harshal Valanda

Reputation: 5451

   NSString *strUrl2 = @"http://fitgritapp.com/admin/services/login.php";

    NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];
    [dataDict setValue:@"[email protected]" forKey:@"email"];
    [dataDict setValue:@"123456" forKey:@"password"];


    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strUrl2 parameters:dataDict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSLog(@"%@",responseObject);

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];

try this

login =     {
        message = "";
        status = success;
        user =         {
            "created_on" = "2017-01-18 12:26:01";
            email = "[email protected]";
            "facebook_id" = "";
            "first_name" = Dipesh;
            id = 4;
            "is_active" = 1;
            "last_name" = Sisodiya;
            password = 123456;
            "password_reset_token" = "";
            "updated_on" = "0000-00-00 00:00:00";
        };
    };

Upvotes: 2

Related Questions