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);
        }];
    }
  • 相关阅读:
    常用正则表达式
    偶得
    监控文件夹里面文件修改的小程序
    使用Windows服务发布WCF服务
    查看wcf服务中方法测试客户端
    twitter注册使用指南
    打包工具使用下载
    c#多线程编程
    请确保此文件可访问并且是一个有效的程序集或COM组件
    添加Service Reference, 无法为服务生成代码错误的解决办法
  • 原文地址:https://www.cnblogs.com/mkai/p/6807601.html
Copyright © 2011-2022 走看看