我是科技高 2014-08-19 02:56
浏览 1188

用AFNetworking 上传图片问题!

UIImageView *imageView1 = (UIImageView *)[self.view viewWithTag:200];

    NSData *data = UIImagePNGRepresentation(imageView1.image);

    NSString *S = [data base64Encoding];

// NSString *path = KUploadDectFile;

    NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"AB000990",@"RecordId",@"1",@"SeqNO",@"",@"URL",@"2014-8-18",@"UploadDate", nil];
    NSString *str = [dic JSONString];

    NSLog(@"str = %@",str);
    NSDictionary *dic1 = [[NSDictionary alloc] initWithObjectsAndKeys:str,@"json",S,@"fileString",nil];

    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.200:8002"]];

// AFHTTPClient *httpClient = [CNGlobal shareGlobal].httpClient;

    /*
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/PhoneService.asmx/UploadDectFile" parameters:dic1];

    [request setHTTPBody:data];

    AFHTTPRequestOperation *operation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"成功!");
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"失败! error = %@",error);
    }];

    [httpClient enqueueHTTPRequestOperation:operation];
    */
    NSURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/PhoneService.asmx/UploadDectFile" parameters:dic1 constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

        [formData appendPartWithFileData:data name:@"IMAGE" fileName:@"face.png" mimeType:@"image/png"];
    }];

// [AFHTTPRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

    AFHTTPRequestOperation *operation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"成功!");

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"失败! error = %@",error);
    }];

    [httpClient enqueueHTTPRequestOperation:operation];

这是我上传图片的代码~ 老是错误提示code = -1011

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 slam rangenet++配置
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊