Search code examples
iosafnetworking-2

Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:]


Whenever i run this function i get assertion error, what should i do

   [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *link = [NSString stringWithFormat:@"%@device_model_no=%@&device_serial_no=%@&device_imei=%@&note=%@&disclaimer=%@&extra_note=%@&package_plan=%@&price=%@&duration=%@&device=%@&user_reg_id=%@&device_category=%@",KURL,txtModelNumber.text,txtSerialNo.text,txtIMEI.text,txtViewExtra.text,deviceDisclamer,additonalDetail.text,plan,price,duration,deviceName,userID,nil];
    NSLog(@"%@",link);

    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

    [manager GET:link parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);


        NSLog(@"%@", responseObject);

        NSDictionary *returnedDealDict = responseObject ;
        NSArray *returnArray = [returnedDealDict objectForKey:@"result"];

        for(NSDictionary *dealDict in returnArray)
        {
            if ([dealDict objectForKey:@"success"])
            {
                ALERT_VIEW(@"Thanks1! Your information has been saved Successfully! We will contact you soon.")
            }
            else
            {
                ALERT_VIEW(@"Your information doesn t exist in our database, Please go back and enter your contact info again!")
            }
        }
        success();

        [MBProgressHUD hideHUDForView:self.view animated:YES];




    }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             NSLog(@"Error: %@", error);
             ALERT_VIEW(@"Error occured while loading data.");
             NSLog(@"getBrandDevice Error");
             [MBPro

gressHUD hideHUDForView:self.view animated:YES];
             }];

I get this error

** Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:], /Users/ios2/Desktop/untitled folder/PhablatFIx/PhablatFIx/MVC/Model/AFNetworking/AFURLRequestSerialization.m:277
    2014-09-25 10:33:26.733 PhablatFIx[721:90b]

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString' * First throw call stack:


Solution

  • you need to add this line of code in order to avoid invalid parameter url string

     NSString *encoded = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];