如何接受HTML回复?

时间:2017-05-15 10:03:43

标签: ios afnetworking-3

你看,响应正文是html,我怎么能接受呢?

enter image description here

我得到以下问题:

  

错误==无法读取数据,因为格式不正确。

我的请求方法如下:

+ (void)AFPOSTWithHud:(BOOL)hud andWholeAddressname:(NSString*)addressName parmas:(NSDictionary*)parmas RequestSuccess:(void(^)(id result))success failBlcok:(void(^)(void))failBlcok {

    if (hud) {
        //[HUD addHUD];

        [SVProgressHUD show];
    }

    AFHTTPSessionManager *requestManager = [Mysevers sharedHTTPSession];

    DLog(@"%@",addressName);

    [requestManager POST:addressName parameters:parmas progress:^(NSProgress * _Nonnull uploadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (hud) {
            //[HUD removeHUD];
            [SVProgressHUD dismiss];
        }
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        if (error != nil) {
            DLog(@"error==%@",[error localizedDescription]);
            if (hud) {
                //[HUD removeHUD];
                [SVProgressHUD dismiss];
            }
            failBlcok();
        }

        return ;
    }];

}

....

+ (AFHTTPSessionManager *)sharedHTTPSession{
    static dispatch_once_t onceToken;
    static AFHTTPSessionManager *requestManager ;
    dispatch_once(&onceToken, ^{
        requestManager = [AFHTTPSessionManager manager];
        requestManager.requestSerializer.timeoutInterval = 10;
        AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
        [serializer setStringEncoding:NSUTF8StringEncoding];
        requestManager.requestSerializer=serializer;

        requestManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];

    });

    return requestManager;
}

您看到我已将acceptabeContentTypes添加到text/html

0 个答案:

没有答案