【发布时间】:2017-06-23 03:32:07
【问题描述】:
我是 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。
【问题讨论】:
标签: ios objective-c json nsurl