// 上传头像到服务器
//     !!!!!!
        // 上传头像到服务器
//        if (image == nil) return;
    
        // 1.创建一个管理者
        AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    
        // 2.封装参数(这个字典只能放非文件参数)
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        params[@"userid"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"userid"];
//        params[@"age"] = @20;
        params[@"orderid"] = @"dB52LYrfisit1UmcWy2jtcaVkM%2BDX9tnzIouhkfMLjufFuXqNS2w8B4H4gcpZ1xugvNlO29TienucrgYPO30tg%3D%3D";
        params[@"shopid"] = @"BXvptI7%2BUHLleiMqhxVS56eB0mXYDnIgVb7ZI8RErX4yxDDG1Yd6OnDBMf5UT4pPy2CGWNtq1w%2FgDDBeLJaIBQ%3D%3D";
    params[@"us"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"us"];
    
    //    字典转JSON字符串
    SBJsonWriter *write = [[SBJsonWriter alloc] init];
    NSString *str2 = [write stringWithObject:params];
    
    NSDictionary *DIC = @{@"s":str2};
    
        // 2.发送一个请求
        NSString *url = [NSString stringWithFormat:@"http://%@/cfm/app/index.php/mycomm/comm", ServiceURL];
        [mgr POST:url parameters:DIC constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            if (UIImagePNGRepresentation(image)) {
                NSData *fileData = UIImagePNGRepresentation(image);
                [formData appendPartWithFileData:fileData name:@"fupload" fileName:@"1.png" mimeType:@"image/png"];
                NSLog(@"aa");
            } else {
                NSData *fileData = UIImageJPEGRepresentation(image, 1.0);
                [formData appendPartWithFileData:fileData name:@"fupload" fileName:@"1.jpg" mimeType:@"image/JPEG"];
                NSLog(@"bb");
            }
    
        } success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"%@", responseObject);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kpyue/article/details/49946955
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

// 上传头像到服务器

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭