我是IOS和Objective C的新手。我正在尝试将值发布到URl并使用AFHTTPSessionManager获取响应。但我得到了错误AFHTTPSession Failure : The data couldn’t be read because it isn’t in the correct format.
这是我的代码
- (void)submitForgetPasswordRequest:(NSString *)email {
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSDictionary *dict = @{@"Email": email};
// NSLog(@"Login dicxtionary : %@", dict);
MBProgressHUD *hud;
hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.label.text = @"Please wait. Logging in...";
[hud showAnimated:YES];
// send user login data to hosting via AFHTTP Async Request in AFNetworking
[manager POST:BASEURL parameters:dict success:^(NSURLSessionTask *task, NSString* responseObject) {
[hud hideAnimated:YES];
// Login response validation
NSLog(@"Raw response object : %@", responseObject);
if ([responseObject isEqualToString:@""]) {
[self showErrorMessage:@"Request failed" Message:@"Please try again later!"];
}else {
// NSError *error = nil;
//NSLog(@"response type : %@", NSStringFromClass([responseObject class]));
// NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
NSLog(@"Response password Reset : %@", responseObject);
[self showErrorMessage:@"Success" Message:@"A password reset link has been send to your email address."];
}
} failure:^(NSURLSessionTask *task, NSError *error) {
NSLog(@"AFHTTPSession Failure : %@", [error localizedDescription]);
}];
}
有人可以帮我解决这个问题。 TNX。
答案 0 :(得分:0)
您也可以使用此行,然后检查
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];