zoukankan      html  css  js  c++  java
  • iOS开发

    - (AFHTTPSessionManager *)getSessionManger{
            
        AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
        AFJSONResponseSerializer *serializer = [AFJSONResponseSerializer serializer];
        serializer.removesKeysWithNullValues = YES;
        serializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/javascript",@"text/json",@"text/plain",@"text/html",@"application/zip", nil];
        sessionManager.responseSerializer = serializer;
        
        return sessionManager;
    }
    
    
    - (void)uploadImageWithUrl:(NSString *)url
                    parameters:(NSDictionary *)parameter
                        images:(NSArray *)images
               timeoutInterval:(NSTimeInterval)timeInterval
                  successBlock:(JZGNetworkRequestSuccessBlock)successBlock
                  failureBlock:(JZGNetworkRequestFailureBlock)failureBlock
    {
        AFHTTPSessionManager *sessionManager = [self getSessionManger];
        NSTimeInterval timeIntervals = 0;
        if ([images count] >= 3) {
            timeIntervals = ([images count] / 3  + 1) * timeInterval;
        }else
            timeIntervals = timeInterval;
        sessionManager.requestSerializer.timeoutInterval = timeIntervals;
        NSDictionary *parameters = [JZGEncyptClass parameterSortWithDictionary:parameter];
        [sessionManager POST:url parameters:parameters
                  constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            for (NSInteger i = 0; i < [images count]; i++) {
                [formData appendPartWithFileData:[images objectAtIndex:i] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg"];
            }
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            NSLog(@"%@",uploadProgress);
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSLog(@"%@",responseObject[@"Message"]);
            NSInteger code = 0;
            NSString *msg = @"";
            if (responseObject) {
                NSString *success   = responseObject[@"success"];
                code                = success.intValue;
                msg                 = responseObject[@"msg"];
            }
            successBlock(responseObject,code,msg);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            failureBlock(error);
        }];
    }
    - (void)uploadImageZipWithUrl:(NSString *)url
                       parameters:(NSDictionary *)parameter
                    imagesZipPath:(NSURL *)imagesZipPath
                     successBlock:(JZGNetworkRequestSuccessBlock)successBlock
                     failureBlock:(JZGNetworkRequestFailureBlock)failureBlock
    {
    
        AFHTTPSessionManager *sessionManager = [self getSessionManger];
        NSDictionary *parameters = [JZGEncyptClass parameterSortWithDictionary:parameter];
        NSLog(@"%@",parameters);
        [sessionManager POST:url parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            [formData appendPartWithFileURL:imagesZipPath name:@"file" fileName:@"file.zip" mimeType:@"application/zip" error:nil];
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            NSLog(@"%@",uploadProgress);
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSLog(@"%@",responseObject[@"msg"]);
            NSInteger code = 0;
            NSString *msg = @"";
            if (responseObject) {
                NSString *success   = responseObject[@"success"];
                code                = success.intValue;
                msg                 = responseObject[@"msg"];
            }
            successBlock(responseObject,code,msg);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"%@",error);
            failureBlock(error);
        }];
    }
  • 相关阅读:
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    软件工程实践总结
  • 原文地址:https://www.cnblogs.com/mkai/p/6807601.html
Copyright © 2011-2022 走看看