关闭

// 上传头像到服务器

140人阅读 评论(0) 收藏 举报
//     !!!!!!
        // 上传头像到服务器
//        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);
        }];


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:21403次
    • 积分:494
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:29篇
    • 译文:0篇
    • 评论:0条
    文章分类