1
在我的項目中,我需要向客戶端發送電子郵件,但我面臨斷言失敗無效的參數。我檢查了所有解決方案,但沒有解決問題。使用URL參數聲明失敗
-(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];
}];
}
錯誤:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString'
它的意圖是'query'分隔符?'是在'path'的最後一個'/'之後出現的嗎? – vadian
嘗試使用URL編碼您的參數。您的網址中可能有空格或其他非網址字符,因爲您直接替換了該處的電子郵件地址和客戶名稱。請參閱http://stackoverflow.com/questions/718429/creating-url-query-parameters-from-nsdictionary-objects-in-objectivec瞭解如何更優雅地做到這一點。 –
是啊,它是@vadian – Arun