我正在尝试对用户进行身份验证,但我的应用程序因错误“NSInternalInconsistencyException”而继续崩溃,原因是:'无效参数不满意:urlRequest'我做错了什么?
以下是我的代码
-(IBAction)btnLogin:(id)sender
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager alloc];
NSDictionary *parameters = @{@"email": email.text, @"pass": pword.text};
NSString *str = @"http://www.blablablabla/api2/user.php?type=login";
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"POST" URLString:str parameters:parameters];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
//[operation setCredential:credential];
[operation setResponseSerializer:[AFJSONResponseSerializer alloc]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
}];
[manager.operationQueue addOperation:operation];
}
答案 0 :(得分:0)
您似乎正在分配AFHTTPRequestOperationManager,但是它是否曾进行过初始化?
另外,在将请求传递给AFHTTPRequestOperation之前检查nil请求。
检查参数并为nil分配已创建的实例可以帮助您立即告知问题所在。
希望这有帮助。