2 u013173634 u013173634 于 2014.08.19 10:56 提问

用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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!