0

I have a form for user. After filling it, the user clicks the submit button and its data is submitted to server. I'm getting an issue that I get response null but my data from the form is successfully submitted to server. I don't know where the issue is coming. I want to run another function if response comes true. My code is this:

    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

    NSString *urlLinkA=@"My URL";


    NSURL * url = [NSURL URLWithString:urlLinkA];

    NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];

    NSString *parameters = [NSString stringWithFormat:@"%@",Parameter];


    NSLog(@"parameter %@",parameters);
    [urlRequest setHTTPMethod:@"POST"];

    [urlRequest setHTTPBody:[parameters dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest
                                                       completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                           [_indicator stopAnimating];
                                                           _indicator.hidden=YES;
                                                           NSLog(@"Response:%@ %@\n", response, error);

                                                           NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

                                                           NSLog(@"DDD %@",dictionary);

                                                           NSString *userid = [dictionary valueForKey:@"property_id"];
                                                           NSLog(@"UserID: %@", userid);



                                                           NSLog(@"Response: %@", dictionary);

                                                           if ([dictionary isEqual:@""]) {
                                                               [self Images];
                                                           }

                                                           HomePageViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
                                                           [self.navigationController pushViewController:presales animated:YES];

                                                           NSString *msg=@"Successfully Registered";

                                                           UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Success"
                                                                                                                          message:msg
                                                                                                                   preferredStyle:UIAlertControllerStyleAlert];

                                                           [self presentViewController:alert animated:YES completion:nil];

                                                           int duration = 2; // duration in seconds

                                                           dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                                                               [alert dismissViewControllerAnimated:YES completion:nil];
                                                           });

                                                       }];


    NSLog(@"network error :");
    [dataTask resume];
}
Sushil Sharma
  • 2,321
  • 3
  • 29
  • 49
Hamza Imran
  • 189
  • 1
  • 18

1 Answers1

1

Please try with postman or RestClient in your browser and debug your post request, it might be possible that server is not sending you proper response. you can download it from https://restlet.com here.

Pankaj K.
  • 535
  • 8
  • 18