AFHTTPSession 失败:无法读取数据,因为它的格式不正确
AFHTTPSession Failure : The data couldn’t be read because it isn’t in the correct format
我是 IOS 和 Objective C 的新手。我正在尝试将 post 值设置为 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.
你也可以使用这一行然后检查
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
我是 IOS 和 Objective C 的新手。我正在尝试将 post 值设置为 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.
你也可以使用这一行然后检查
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];