0

I am trying to connect to an Api but it is using x-www-form-urlencoded ...and i am using this code .Plz tell me the correct method

AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;


AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = nil;
manager.securityPolicy = securityPolicy;

[manager POST:[NSString stringWithFormat:@"@"%@%@phone=%@&password=%@",BASE_URL,API_LOGIN,phone,password]
   parameters:nil
      success:^(AFHTTPRequestOperation *operation, id responseObject) {

          successBlock(responseObject);

      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

          NSLog(@"Server Error : %@", operation.responseString);
          errorBlock(error);
      }];

}

Subhojit Mandal
  • 450
  • 4
  • 13

1 Answers1

1

I think you should try to set the http header for 'x-www-form-urlencoded' to communicate with your backend:

[manager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

If this does not fix your errors, then try to validate your json object.
You could also have a look to this question: AFNetworking 3 x-www-form-urlencoded post data

Community
  • 1
  • 1
weissja19
  • 535
  • 4
  • 11