AFNetworking 2.0 Get JSON from code 400 in failure block

前端 未结 4 2042
长发绾君心
长发绾君心 2021-01-05 09:33

I\'m using AFHTTPRequestOperationManager for a POST request. Now I\'m deliberately entering incorrect information to handle a 400 erro

4条回答
  •  死守一世寂寞
    2021-01-05 09:51

    I also faced same problem in AFNetworking, as instead of using

    - (NSURLSessionDataTask *)POST:(NSString *)URLString
                    parameters:(id)parameters
                      progress:(void (^)(NSProgress * _Nonnull))uploadProgress
                       success:(void (^)(NSURLSessionDataTask * _Nonnull, id _Nullable))success
                       failure:(void (^)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure
    

    Please try to use that one :-

    - (NSURLSessionDataTask *)POST:(NSString *)URLString
                    parameters:(id)parameters
     constructingBodyWithBlock:(void (^)(id  formData))block
                      progress:(nullable void (^)(NSProgress * _Nonnull))uploadProgress
                       success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                       failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
    

    thanks,

提交回复
热议问题