1


In my project, I need to send email to the client but I am facing with assertion failure invalid parameters. I have checked all solutions but it's not working out.

-(void)EmailWebservice
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    manager.requestSerializer = serializer;

    NSString *getPostLink = [NSString stringWithFormat:@"http://Dummy.com/sendmail/?business_email=%@&_name=%@",TextEmail.text,[[NSUserDefaults standardUserDefaults]valueForKey:@"USERNAME"]];

    NSString *encoded = [getPostLink stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"Encoding value is %@",encoded);

    [manager GET:getPostLink parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"JSON: %@", responseObject);
        [MBProgressHUD hideHUDForView:self.view animated:YES];

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

        NSLog(@"the failure is %@", error);
        [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];
}

Error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString'

Arun
  • 624
  • 4
  • 18
  • Is it intended that the `query` separator `?` comes right after the last `/` of the `path`? – vadian Jan 05 '16 at 12:43
  • Try URL-encoding your parameters. You probably have spaces or other non-URL characters in your URL because you're directly substituting the email address and customer name in there. See http://stackoverflow.com/questions/718429/creating-url-query-parameters-from-nsdictionary-objects-in-objectivec for how to do this more elegantly. – Eric Galluzzo Jan 05 '16 at 12:43

1 Answers1

0

The error is telling you that there is something wrong with your URL. I would start by printing out the url as you are doing with the line:

NSLog(@"Encoding value is %@",encoded);

Can you paste this into a browser of your choice and see if the page loads?

You might trying hard coding values for the parameters in your url:

business_email
fave_customer_name

Encode your parameters:

-(void)EmailWebservice
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    manager.requestSerializer = serializer;

    NSString *email = [TextEmail.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString customer = [[NSUserDefaults standardUserDefaults]valueForKey:@"USERNAME"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString *getPostLink = [NSString stringWithFormat:@"http://Dummy.com/csrestapi/sendintroemail/?business_email=%@&fave_customer_name=%@",email,customer];

    NSString *encoded = [getPostLink stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"Encoding value is %@",encoded);

    [manager GET:getPostLink parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"JSON: %@", responseObject);
        [MBProgressHUD hideHUDForView:self.view animated:YES];

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

        NSLog(@"the failure is %@", error);
        [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];
}

You should read this stackoverflow question as it covers this type of issue.

Community
  • 1
  • 1
Peter Hornsby
  • 4,208
  • 1
  • 25
  • 44