How to send blank data to parameters while sending POST request using AFHTTPSessionManager

45 Views Asked by At

I am new to REST API's. I am trying to send some data to Web apis using POST method. Everything runs fine, until i try to send blank data to parameter. Here below is my code for the same

[dict setObject:strReqId forKey:@"ReqId"];
[dict setObject:strOrderId forKey:@"OrderId"];
[dict setObject:strScheduleId forKey:@"ScheduleId"];
 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

manager.securityPolicy.allowInvalidCertificates = YES;
manager.securityPolicy.validatesDomainName = NO;
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

[manager POST:URLString parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject){
    NSLog(@"%@",responseObject);

    NSString *strResponse = [NSString stringWithFormat:@"%@",responseObject];
    if (strResponse.length>0)
    {
        if ([strResponse isEqualToString:@"0"])
        {
            UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Warning!", nil)] message:[NSString stringWithFormat:NSLocalizedString(@"Something went wrong. Please try again.", nil)] delegate:self cancelButtonTitle:nil otherButtonTitles:[NSString stringWithFormat:NSLocalizedString(@"OK", nil)],nil];
            [alert3 show];
        }
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)  {

}];

but when i try to send blank data to any parameter like,

[dict setObject:@"" forKey:@"ReqId"];

i get a "0" in response. Please help me.

1

There are 1 best solutions below

2
Emon On

[dict setObject:@[] forKey:@"ReqId"]; try that. Actually you have to pass any type data with that. here @[] meaning empty array.