URL参数断言失败

时间:2016-01-05 12:38:34

标签: objective-c url assertions


在我的项目中,我需要向客户端发送电子邮件,但我面临断言失败无效参数。我检查了所有解决方案,但它没有成功。

^(?:[^-]|-(?:[^cw].?|c[^l]|w[^fl])-|-.{2}[^-])*_thanks

错误:

  

由于未捕获的异常而终止应用   ' NSInternalInconsistencyException',原因:'无效参数不   满足:URLString'

1 个答案:

答案 0 :(得分:0)

错误告诉您网址有问题。我首先打印出你正在使用该行的URL:

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

您可以将其粘贴到您选择的浏览器中,看看页面是否加载了吗?

您可能会尝试对网址中的参数进行硬编码:

business_email
fave_customer_name

对参数进行编码:

-(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];

    }];
}

您应该阅读此stackoverflow question,因为它涵盖了此类问题。