【问题标题】:AFHTTPSession Failure : The data couldn’t be read because it isn’t in the correct formatAFHTTPSession 失败:由于格式不正确,无法读取数据
【发布时间】: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


    【解决方案1】:

    你也可以使用这条线然后检查

    manager.requestSerializer = [AFJSONRequestSerializer serializer];
       manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 1970-01-01
      • 2016-10-15
      相关资源
      最近更新 更多